tinder-1.excalidraw
tinder-2.excalidraw
5. High-Level Design
Mobile Client
|
API Gateway
|
-------------------
| |
Profile Service Swipe Service
| |
Profile DB Swipe DBProfile 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 usersNotifications:
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 AWith 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 notificationsSimple but delayed.
Solution 2 (Redis)
Use Redis for match lookup.
Redis Key:
userA:userBWorkflow:
Write swipe
Check inverse swipe atomically
Create matchWhy?
- Redis is single-threaded.
- Supports atomic operations.
Solution 3 (PostgreSQL)
Store both decisions in same row.
User1
User2
User1Decision
User2DecisionPostgres row locking + ACID guarantees consistency.
9. Deep Dive #2 — Fast Stack Loading
Current Problem
Query:
Find nearby users
Filter by preferencesExpensive because:
- Geospatial queries
- Latitude/Longitude search
Solution A: Precompute Stack
Nightly job:
Cron Job
↓
Generate recommendations
↓
Store in CacheUser request:
Cache Hit → Return immediatelyPros:
- Very fast
Cons:
- Cache invalidation
Solution B: Geospatial Index
Option 1
PostgreSQL + PostGIS
Supports:
Location-based indexingOption 2
Elasticsearch
Profile DB
|
CDC
|
ElasticsearchBenefits:
- Fast geospatial search
- Fast filtering
10. Deep Dive #3 — Avoid Repeat Profiles
Simple Solution
Get recommendation stack
Get previous swipes
Remove duplicates
Return resultWorks but expensive.
Better Solution
Maintain cache:
User
→
Set of Swiped UsersExample:
User123
→ {User5, User9, User21}Fast lookup.
Bloom Filter Optimization
Why? Storage becomes huge:
10M users
100 swipes/day
365 days
≈ 36.5 TBUse Bloom Filter:
Pros:
- Very space efficient
Cons:
- False positives possible