System Design AI

Design a Social Graph Service: Junior, Senior and Staff Answers

When you get asked to design a social graph service, the interviewer is looking for three things: how you break down a request into components, how you model the data for fast neighbor look-ups, and how you reason about scale, reliability, and cost. The question is a classic way to probe your ability to think about high-read, moderate-write workloads and to articulate the engineering trade-offs that keep a billion-scale service running.

What the interview tests

  • Scalability – Can you estimate traffic, shard data, and keep latency low?
  • Data modeling – Do you choose a storage layout that supports "friends of a user" queries efficiently?
  • Operational awareness – Do you think about monitoring, failure isolation, and cost?
  • Communication – Can you explain your design step-by-step, and justify each choice?

Core requirements and driving numbers

RequirementTypical ballpark
Number of users~100 million (on the order of 10⁸)
Average friends per user~200 (roughly a few hundred)
Read-heavy traffic1 million requests per day ≈ 12 req/s, but in a real service you may see 10 × that during peak hours, so design for ~120 req/s
Write frequencyAbout 5 % of reads, mainly friend adds/removes
Latency target< 100 ms for read, < 200 ms for write

These numbers drive the choice of storage, caching, and request routing. A social graph is essentially a many-to-many relationship, so the data model must allow fast retrieval of a user’s adjacency list.

Core design – request path one hop at a time

  1. API Gateway – Receives the HTTP request (e.g., GET /users/123/friends). It validates auth tokens and forwards to a Lambda.
  2. Lambda (or small EC2 service) – Parses the request, decides whether it is a read or write. For a read, it checks the cache first.
  3. Cache layer (ElastiCache – Redis) – Stores the adjacency list for hot users. A cache miss triggers a DB fetch.
  4. Primary store (DynamoDB) – Holds the graph edges. The table uses a composite primary key: PK = USER#<user_id>, SK = FRIEND#<friend_id>. This layout lets you query all friends of a user with a single partition-key query.
  5. Write path – For a friend add, the service writes two items (bidirectional edge) to DynamoDB in a transaction, then invalidates the relevant cache entries.
  6. Async processing (SQS + Lambda) – Optional fan-out for activity feeds or recommendation pipelines.
  7. Observability – CloudWatch metrics for request latency, cache hit ratio, and DynamoDB throttling; alarms trigger SNS notifications.

Data model details

  • Edges table – Each edge is a separate item. An inverted global secondary index (partition key SK, sort key PK) allows reverse look-ups (who follows a user) if needed.
  • User profile table – Separate DynamoDB table for static user data; not part of the graph but often needed for response enrichment.
  • Why DynamoDB over Aurora? DynamoDB gives single-digit millisecond latency, auto-scaling, and a simple key-value access pattern that matches the adjacency-list query. Aurora would require complex joins or materialized views, adding latency and operational burden.

What a complete junior answer covers

  • Lists the functional requirements (add friend, remove friend, list friends).
  • Mentions non-functional goals (latency, scalability) with rough numbers.
  • Draws a simple flow: API → Lambda → DynamoDB.
  • Chooses DynamoDB for storage and explains the primary-key schema.
  • Shows a basic cache (ElastiCache) as an optional improvement.
  • Identifies a single point of failure (for example, a single-node Redis cache) and suggests adding redundancy.

What a senior answer adds

  • Sharding strategy – Uses a hash of user_id to distribute partitions evenly across DynamoDB partitions.
  • Cache strategy – Describes TTL, write-through vs. write-behind, and cache-invalidation on friend updates.
  • Consistency – Explains DynamoDB's eventual consistency for reads and the need for transactions on writes to keep edges symmetric.
  • Rate limiting – Adds API Gateway throttling to protect the backend.
  • Monitoring – Details CloudWatch dashboards for cache hit ratio, DynamoDB read/write capacity, and Lambda error rates.
  • Cost awareness – Rough estimate of DynamoDB read/write units and Redis node pricing.

What a staff answer adds

  • Failure modes – Analyzes scenarios: cache miss storms, DynamoDB hot partitions, network partitions, and Lambda timeout spikes. Proposes circuit breakers and exponential back-off.
  • Operational runbooks – Outlines steps to rebalance shards, scale Redis clusters, and recover from a partial outage.
  • Cost optimization – Suggests on-demand vs. provisioned capacity, reserved instances for Redis, and data lifecycle policies in S3 for archival of old edges.
  • Trade-off defense – Defends the choice of DynamoDB over a graph-native store (e.g., Neptune) by citing lower latency for adjacency queries, simpler scaling, and lower operational overhead.
  • Future extensions – Mentions how to add multi-hop queries using a pre-computed neighbor table or a batch processing job on EMR.

Common mistakes that sink the question

MistakeWhy it hurts
Treating the graph as a relational joinLeads to costly cross-table joins and high latency.
Ignoring write symmetryResults in inconsistent friend relationships and extra repair jobs.
Forgetting to shard DynamoDBCauses hot partitions when a few users become very popular.
No caching strategyIncreases read latency and DB cost dramatically.
Over-engineering with a full-graph databaseAdds unnecessary operational complexity for a simple adjacency-list use case.

Comparison of answer depth by level

AspectJuniorSeniorStaff
RequirementsLists basic CRUD, mentions latencyAdds scaling numbers, rate limiting, consistencyIncludes SLA targets, cost model, ops runbooks
Data modelSimple DynamoDB schemaSharding, secondary indexes, cache strategyFailure analysis, trade-off justification
ComponentsAPI → Lambda → DynamoDBAdds ElastiCache, CloudWatch, throttlingAdds SQS for async, circuit breakers, runbooks
Operational concernsBasic redundancyMonitoring, alerts, capacity planningDetailed runbooks, cost optimization, disaster recovery
Mistake handlingAcknowledges single point of failureDiscusses hot partitions, cache invalidationProvides mitigation plans for multiple failure modes

How to practice this

  1. Study the worked design – Open the creator recommendations (who to follow) design in the System Design AI library, a related design. Walk through each step and note why each component was chosen.
  2. Sketch your own canvas – Use the practice brief to draw the request flow, label the DynamoDB keys, and indicate where you would place caching and async components.
  3. Review with the AI coach – Submit your canvas for feedback. Focus on the areas where staff-level answers differ: failure modes, cost, and trade-off justification.

Questions people ask

What are the main scaling challenges for a social graph service?

The biggest challenges are handling hot users that generate many read requests, keeping adjacency lists small enough for low-latency reads, and ensuring write symmetry without creating hot partitions.

Why choose DynamoDB over a graph database like Neptune?

DynamoDB offers single-digit millisecond latency for key-value look-ups, automatic scaling, and a simpler operational model. A graph database adds complexity and often higher query latency for simple neighbor reads.

How does caching improve read performance in this design?

ElastiCache stores the friend list for frequently accessed users. A cache hit avoids a DynamoDB read, reducing latency from a few milliseconds to sub-millisecond and cutting read-capacity costs.

What operational metrics should I monitor for a social graph service?

Track API latency, cache hit ratio, DynamoDB read/write throttling, Lambda error rates, and Redis memory usage. Set alarms on sudden spikes to catch cache-miss storms or hot-partition issues.