Linkedin Senior SWE HLD interview experience
Company: LinkedIn
Role: senior software engineer
Interview Stage: Onsite
Location: unknown
Year: unknown
Original Post Content:
This was for a system design interview at LinkedIn for Senior SWE role. The problem was to design a Truecaller clone, focusing on its core functionalities like reverse phone number lookup and spam identification. It was a fantastic discussion that touched upon many key distributed system concepts.
Here’s a breakdown of how the interview unfolded, including the requirements, my proposed design, and the deeper dives we explored.
The Problem Statement: Design a Truecaller Clone
The primary goal was to build an app that:
- Given a phone number, gets the name associated with it.
- Helps in identifying spam callers.
Initial Requirements (Implicit & Clarified through discussion):
- Functional Requirements (FRs):Reverse Phone Number Lookup (Name to Number).Spam Identification & Flagging.User Contribution: Users can report names and spam.Caller ID Display on incoming calls (mobile client integration).Search History for users.Blocked Numbers functionality.
- Non-Functional Requirements (NFRs):Scale: Handle millions to hundreds of millions of DAU.Latency: P99 lookup latency < 200ms (aim for 100ms for real-time caller ID).Availability: High availability (99.99% was the target).Reliability/Durability: Data (names, reports) must not be lost.Consistency: Eventual consistency for lookups and user contributions, but leaning towards stronger consistency for spam updates to be effective.
Back-of-the-Envelope Estimations (for 100M DAU):
I quickly jotted down some numbers to align on scale:
- Lookup QPS: Assuming 5 lookups/user/day (calls + manual searches), that's 500M lookups/day. This translates to an average of ~5800 QPS, with a peak of ~12,000 QPS.
- Data Storage: Estimating 500M unique numbers initially, with ~100 bytes/record (number, name, spam count, timestamp, metadata), we're looking at ~50 GB initially, scaling to several TBs over 5-10 years with growth and contributions.
Clarifying Questions I asked the Interviewer:
High-Level Design (HLD)
I proposed a microservices-based architecture to handle the scale and separation of concerns.
Core Components:
- Clients: Mobile Apps (iOS/Android) and Web Client.
- Load Balancer: Distributes incoming requests.
- API Gateway: Central entry point for all API calls. Handles auth, rate limiting, and request routing.
- Web Servers (Frontend Services): Stateless, handle UI rendering and basic API orchestration.
- Lookup Service: Core service for retrieving phone number information.
- Spam Detection Service: Identifies and classifies spam numbers.
- Contribution Service: Ingests user reports (names, spam classifications).
- Notification Service: Pushes real-time caller ID updates to mobile clients.
- Distributed Cache (Redis): For low-latency lookups of frequently accessed data.
- Primary Database(s): Where the actual phone number data, spam info, and user data reside.
- Message Queues (Kafka/RabbitMQ): For asynchronous processing and decoupling services.
- Data Processing / Analytics Pipeline (Spark/Hadoop): For offline analysis, model training, and data aggregation.
- Third-Party PN Services: APNS, FCM for mobile push notifications.
High-Level Data Flow (Reverse Lookup):
Component Deep Dive
We then focused on the Database Layer and Spam Detection/Data Processing due to their criticality.
1. Database Choice & Schema
- Challenge: Massive data, high read/write throughput, hot spots, consistency needs.
- Solution: Hybrid ApproachMain Phone Number Data (Lookup & Spam):Choice: NoSQL Key-Value Store like Apache Cassandra or Amazon DynamoDB.Justification: High availability, horizontal scalability, low latency for key-based lookups, and excellent partition tolerance. Fits an AP (Availability and Partition Tolerance) model, which is crucial for a real-time service where occasional eventual consistency is acceptable.Schema: phone_numbers table/collection.Partition Key: phone_number (ensures even distribution and quick lookups).Columns: name, spam_score (float), spam_category (set of strings), reported_count (counter), last_reported_timestamp, reported_names (map for multiple names), data_version (vector clock for conflict resolution).Sharding: Phone numbers automatically shard across nodes using consistent hashing with virtual nodes for even distribution and fault tolerance.Consistency: Leveraged eventual consistency for lookups, where a slight delay in updates is fine. For writes, discussed tunable consistency using quorum ($N, W, R$), opting for $W < N$ to prioritize write availability and rely on background reconciliation for conflicts.User-Specific Data (Auth, Blocked Numbers, History):Choice: Relational Database like PostgreSQL or MySQL.Justification: ACID properties for strong consistency on sensitive user data, good for structured data and complex joins for user profiles/settings.Schema: users, user_blocked_numbers, user_search_history tables. Sharded by user_id.Scaling: Read replicas and master-slave replication.
2. Spam Detection and Data Processing
- Challenge: High volume of user reports, computationally intensive ML models, need for fresh spam data, asynchronous processing.
- Solution: Asynchronous & Tiered ProcessingData Ingestion: User reports arrive via the Contribution Service and are immediately pushed to a Message Queue (e.g., Kafka). This acts as a buffer and decouples the client-facing API from the processing.Asynchronous Processing (Spam Detection Service):A pool of "Spam Processing Workers" (consumers) continuously pulls messages from the queue.These workers increment reported_count in the database and perform preliminary aggregation.For numbers crossing certain thresholds, they trigger the ML model (or send to another queue for dedicated ML inference workers) to update spam_score and spam_category in the main phone number database.Offline Data Processing & ML Model Training (Analytics Pipeline):A separate batch processing pipeline (e.g., Apache Spark on HDFS) runs periodically (e.g., daily/weekly).Purpose: Retrains the core spam classification ML models using the latest aggregated historical data, performs feature engineering, and identifies new spam trends.Output: Updated ML models and potentially aggregated statistics for the Spam Detection Service.Real-time Feedback Loop (Notification Service):When a number's spam status changes significantly, the Spam Detection Service can trigger the Notification Service.The Notification Service sends push notifications to mobile clients (via APNS/FCM) to update their local caches for that specific number, ensuring immediate display of the latest spam info for active users.
Scalability, Availability & Trade-offs
Scalability:
- Horizontal Scaling: All stateless tiers (Web Servers, API Gateway, Lookup Service, Notification Service) scale horizontally by adding more instances behind load balancers. Auto-scaling groups would automate this.
- Database Scaling: NoSQL (Cassandra/DynamoDB) scales by adding nodes; relational DB scales with sharding and read replicas.
- Caching: Distributed cache offloads database reads, scales independently.
- Message Queues: Decouple services, absorb traffic bursts, allow independent scaling of producers/consumers.
- Worker Pools: Dedicated worker services for async processing scale based on load.
Availability:
- Redundancy: Multiple instances for every service, redundant load balancers.
- Database Replication: Master-slave for relational, native replication for NoSQL.
- Multi-Data Center Deployment: GeoDNS routes users to nearest/healthy data center, data replicated across regions for disaster recovery.
- Decoupling: Message queues prevent cascading failures.
- Failure Detection: Gossip protocol for distributed databases helps quickly identify and route around unhealthy nodes.
- Sloppy Quorum/Hinted Handoff: For temporary NoSQL node failures, ensures writes complete and data eventually syncs.
Key Trade-offs: