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.
- Backend: Node.js + Express + TypeScript
- ORM: Prisma
- Database: PostgreSQL
- Database platform: Supabase
- Deployment: Render
POST /identify
Content-Type: application/json
{
"email": "mcfly@hillvalley.edu",
"phoneNumber": "123456"
}
Both fields are optional, but at least one must be provided.
{
"contact": {
"primaryContatctId": 1,
"emails": ["mcfly@hillvalley.edu"],
"phoneNumbers": ["123456"],
"secondaryContactIds": []
}
}
-
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.
- Clone the Repo
git clone https://github.com/manujayakumar/BackendTask.git
cd BackendTask
- Install Dependencies
npm install
- 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
- Setup Prisma and Migrate
npx prisma init
npx prisma generate
npx prisma migrate dev --name init
- Run the Server
npm run dev
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
}
Use Postman or curl to test:
curl -X POST https://backendtask-wfm0.onrender.com/v1/identify \
-H "Content-Type: application/json" \
-d '{"email": "doc@brown.com", "phoneNumber": "999999"}'
PhoneNumber | Outcome | |
---|---|---|
george@hillvalley.edu | 919191 | Creates primary contact |
biffsucks@hillvalley.edu | 717171 | Creates another primary contact |
george@hillvalley.edu | 717171 | Merges biff's contact as secondary |
This app is deployed using Render.com.
Push to main
automatically redeploys your app.
Way Of Life At Bitespeed
Manu Jayakumar
💼 LinkedIn
📧 manu.jayakumar0@gmail.com