Skip to content

This project implements the /identify endpoint for Bitespeed's identity reconciliation system. It deduplicates and links customer contact information (email and phone numbers) to provide a unified customer identity for FluxKart.com.

Notifications You must be signed in to change notification settings

manujayakumar/BackendTask

Repository files navigation

🧠 Bitespeed Backend Task: Identity Reconciliation

This project implements the /identify endpoint for Bitespeed's identity reconciliation system. It deduplicates and links customer contact information (email and phone numbers) to provide a unified customer identity for FluxKart.com.

🔗 Hosted API Endpoint

🌐 https://backendtask-wfm0.onrender.com/v1/identify


📦 Tech Stack

  • Backend: Node.js + Express + TypeScript
  • ORM: Prisma
  • Database: PostgreSQL
  • Database platform: Supabase
  • Deployment: Render

📘 API Specification

Endpoint

POST /identify

Content-Type: application/json

Request Body

{
  "email": "[email protected]",
  "phoneNumber": "123456"
}

Both fields are optional, but at least one must be provided.

Response Body

{
  "contact": {
    "primaryContatctId": 1,
    "emails": ["[email protected]"],
    "phoneNumbers": ["123456"],
    "secondaryContactIds": []
  }
}

🧠 How It Works

  • Each contact can be linked by matching either email or phoneNumber.

  • The oldest contact becomes primary; the rest are secondary and point to the primary via linkedId.

  • If new data comes in that doesn't match any existing contact, it creates a new primary contact.

  • If new data partially matches existing contacts (e.g. same phone but different email), a new secondary contact is created.

  • If merging two primaries, the older one remains primary and the newer becomes secondary.

🛠️ Setup & Development

  1. Clone the Repo
git clone https://github.com/manujayakumar/BackendTask.git

cd BackendTask
  1. Install Dependencies
npm install
  1. Set Up Environment Variables
    Create a .env file:
DATABASE_URL="postgresql://user:password@host:port/dbname?schema=public"
DIRECT_URL="postgresql://user:password@host:port/dbname?schema=public"
PORT=4000
  1. Setup Prisma and Migrate
npx prisma init
npx prisma generate
npx prisma migrate dev --name init
  1. Run the Server
npm run dev

🗃️ Database Schema

model Contact {
  id             Int       @id @default(autoincrement())
  phoneNumber    String?   
  email          String?   
  linkedId       Int?      
  linkPrecedence LinkPrecedence @default(PRIMARY)
  linkedContact  Contact?       @relation("ContactLink", fields: [linkedId], references: [id])
  contacts       Contact[]      @relation("ContactLink")
  createdAt      DateTime  @default(now())
  updatedAt      DateTime  @updatedAt
  deletedAt      DateTime?

  @@index([email])
  @@index([phoneNumber])
}

enum LinkPrecedence {
  PRIMARY
  SECONDARY
}

🧪 Testing

Use Postman or curl to test:

curl -X POST https://backendtask-wfm0.onrender.com/v1/identify \
  -H "Content-Type: application/json" \
  -d '{"email": "[email protected]", "phoneNumber": "999999"}'

🧾 Example Scenarios

Email PhoneNumber Outcome
[email protected] 919191 Creates primary contact
[email protected] 717171 Creates another primary contact
[email protected] 717171 Merges biff's contact as secondary

📤 Deployment

This app is deployed using Render.com.

Push to main automatically redeploys your app.

📚 References

Way Of Life At Bitespeed

🤝 Author

Manu Jayakumar
💼 LinkedIn
📧 [email protected]

About

This project implements the /identify endpoint for Bitespeed's identity reconciliation system. It deduplicates and links customer contact information (email and phone numbers) to provide a unified customer identity for FluxKart.com.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published