Linkedin Senior SWE HLD interview experience
This was for a system design interview at Linkeding 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:
- "What is the expected growth rate of the user base and data volume (e.g., monthly/yearly percentage increase)?" (Crucial for database scaling strategy).
- "Are there any specific privacy or regulatory compliance requirements (e.g., GDPR, data residency) for storing and processing phone number data?" (This has huge implications for data storage and architecture).
- "How strict is the 'real-time' requirement for caller ID? Is a brief delay of a few seconds acceptable if it allows for more robust spam detection or data fetching?"
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):
- Incoming call on Mobile Client.
- Mobile App sends
GET /lookup?number=<phone>to Load Balancer. - Load Balancer -> API Gateway (Auth, Rate Limit) -> Web Server.
- Web Server calls Lookup Service.
- Lookup Service checks Distributed Cache.
- Cache Hit: Data returned to client immediately.
- Cache Miss: Lookup Service queries Primary Database(s).
- Data retrieved, stored in Cache, and returned to client.
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 Approach
- Main Phone Number Data (Lookup & Spam):
- [cite_start]Choice: NoSQL Key-Value Store like Apache Cassandra or Amazon DynamoDB. [cite: 134, 1960, 1970]
- Justification: High availability, horizontal scalability, low latency for key-based lookups, and excellent partition tolerance. [cite_start]Fits an AP (Availability and Partition Tolerance) model, which is crucial for a real-time service where occasional eventual consistency is acceptable. [cite: 2029]
- Schema:
phone_numberstable/collection.- Partition Key:
phone_number(ensures even distribution and quick lookups). - [cite_start]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). [cite: 1976, 2192]
- Partition Key:
- [cite_start]Sharding: Phone numbers automatically shard across nodes using consistent hashing with virtual nodes for even distribution and fault tolerance. [cite: 1954, 2075, 1853]
- Consistency: Leveraged eventual consistency for lookups, where a slight delay in updates is fine. [cite_start]For writes, discussed tunable consistency using quorum (), opting for to prioritize write availability and rely on background reconciliation for conflicts. [cite: 2054, 2139]
- User-Specific Data (Auth, Blocked Numbers, History):
- Choice: Relational Database like PostgreSQL or MySQL.
- [cite_start]Justification: ACID properties for strong consistency on sensitive user data, good for structured data and complex joins for user profiles/settings. [cite: 131, 2388, 2588, 3385, 3400]
- Schema:
users,user_blocked_numbers,user_search_historytables. Sharded byuser_id. - Scaling: Read replicas and master-slave replication.
- Main Phone Number Data (Lookup & Spam):
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 Processing
- Data Ingestion: User reports arrive via the Contribution Service and are immediately pushed to a Message Queue (e.g., Kafka). [cite_start]This acts as a buffer and decouples the client-facing API from the processing. [cite: 535, 547]
- Asynchronous Processing (Spam Detection Service):
- A pool of "Spam Processing Workers" (consumers) continuously pulls messages from the queue.
- These workers increment
reported_countin 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_scoreandspam_categoryin 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).
- [cite_start]Purpose: Retrains the core spam classification ML models using the latest aggregated historical data, performs feature engineering, and identifies new spam trends. [cite: 3051]
- 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.
- [cite_start]Multi-Data Center Deployment: GeoDNS routes users to nearest/healthy data center, data replicated across regions for disaster recovery. [cite: 470, 500, 2301]
- Decoupling: Message queues prevent cascading failures.
- [cite_start]Failure Detection: Gossip protocol for distributed databases helps quickly identify and route around unhealthy nodes. [cite: 2242]
- [cite_start]Sloppy Quorum/Hinted Handoff: For temporary NoSQL node failures, ensures writes complete and data eventually syncs. [cite: 2283, 2286]
Key Trade-offs:
- Consistency vs. Availability (CAP Theorem):
- Choice: AP for core phone number data (NoSQL) and CP for user-specific data (relational DB).
- Reasoning: Prioritized high availability and low latency for lookups for a real-time caller ID experience. Slight data staleness for names/spam is acceptable in favor of always providing a response. Strong consistency is maintained for critical user data like blocked numbers.
- Latency vs. Data Freshness for Spam Detection:
- Choice: Asynchronous processing of user spam reports via message queues, with batch processing for ML model retraining.
- Reasoning: Immediate, synchronous processing of every single spam report would be too resource-intensive and add latency. A slight delay in a number becoming fully classified as spam is generally acceptable as it often requires multiple reports.
- Storage Cost vs. Read Performance:
- Choice: Tiered storage: hot data in cache/fast NoSQL, warm data in standard DB, cold data (old reports/logs) in archival storage.
- Reasoning: Optimizes for cost while ensuring low latency for frequently accessed data.
Further Considerations & Follow-up Prompts
- Security: Data encryption (at rest/in transit), robust access control, privacy considerations (anonymization of reports).
- Monitoring & Alerting: Comprehensive metrics (QPS, latency, errors, resource utilization) and proactive alerting.
- Internationalization: Support for different numbering formats, country codes, and languages.
- Data Quality: Strategies to handle malicious or incorrect user contributions (e.g., reporter reputation systems, anomaly detection).
- Potential Follow-up Areas for Interviewer:
- Diving deeper into the specific ML algorithms and feature engineering for spam detection.
- Detailed discussion on conflict resolution strategies using vector clocks in the NoSQL database.
- Client-side architecture, especially for efficient real-time caller ID integration on mobile (battery, data usage optimization).
Overall, it was a very engaging and challenging interview that required thinking about trade-offs at every layer of the system. I felt I was able to clearly articulate my design choices and justify them based on the requirements. Hopefully, this helps others preparing for similar interviews!


