tinder-1.excalidraw

tinder-2.excalidraw


5. High-Level Design

Mobile Client
      |
 API Gateway
      |
 -------------------
 |                 |
Profile Service  Swipe Service
 |                 |
Profile DB      Swipe DB

Profile Service

Responsible for:

  • Store preferences
  • Fetch candidate profiles

Swipe Service

Responsible for:

  • Store swipes
  • Detect matches
  • Send notifications

6. Database Choice

Profile DB

Can use:

  • PostgreSQL
  • MySQL

Reason:

  • Moderate traffic
  • Relational data

Swipe DB

Heavy write workload. Options:

Cassandra

Pros:

  • Optimized for writes
  • Handles 100K+ writes/sec

PostgreSQL

Pros:

  • Strong ACID guarantees
  • Easier consistency handling

Trade-off:

  • More nodes required

7. Match Detection

When User B swipes right:

1. Save swipe
2. Check inverse swipe
3. If exists:
      Create Match
      Notify both users

Notifications:

iOS

  • Apple Push Notification Service (APNS)

Android

  • Firebase Cloud Messaging (FCM)

8. Deep Dive #1 — Consistency

Problem

Both users swipe right simultaneously.

A likes B
B likes A

With eventual consistency:

A cannot see B's swipe
B cannot see A's swipe

→ Match missed.


Solution 1

Accept eventual consistency.

Run reconciliation job:

Hourly Job

Find missed matches

Send notifications

Simple but delayed.


Solution 2 (Redis)

Use Redis for match lookup.

Redis Key:
userA:userB

Workflow:

Write swipe
Check inverse swipe atomically
Create match

Why?

  • Redis is single-threaded.
  • Supports atomic operations.

Solution 3 (PostgreSQL)

Store both decisions in same row.

User1
User2
User1Decision
User2Decision

Postgres row locking + ACID guarantees consistency.


9. Deep Dive #2 — Fast Stack Loading

Current Problem

Query:

Find nearby users
Filter by preferences

Expensive because:

  • Geospatial queries
  • Latitude/Longitude search

Solution A: Precompute Stack

Nightly job:

Cron Job

Generate recommendations

Store in Cache

User request:

Cache Hit → Return immediately

Pros:

  • Very fast

Cons:

  • Cache invalidation

Solution B: Geospatial Index

Option 1

PostgreSQL + PostGIS

Supports:

Location-based indexing

Option 2

Elasticsearch

Profile DB
     |
CDC
     |
Elasticsearch

Benefits:

  • Fast geospatial search
  • Fast filtering

10. Deep Dive #3 — Avoid Repeat Profiles

Simple Solution

Get recommendation stack
Get previous swipes
Remove duplicates
Return result

Works but expensive.


Better Solution

Maintain cache:

User

Set of Swiped Users

Example:

User123
→ {User5, User9, User21}

Fast lookup.


Bloom Filter Optimization

Why? Storage becomes huge:

10M users
100 swipes/day
365 days
≈ 36.5 TB

Use Bloom Filter:

Pros:

  • Very space efficient

Cons:

  • False positives possible