← LinkedIn Interview InsightsSoftware Engineer

LinkedIn·Software Engineer·Onsite - System Design / Architecture·Senior

SeniorPrefer not to say
Jun 2026

Summary

LinkedIn system design round, basically a follow-up to an earlier BFS coding question but scaled up to a production context. No coding, just a long discussion about how you'd actually run that algorithm on a graph with hundreds of millions of nodes. Way more open-ended than I expected.

Questions Asked (1)

Q1

You've built a BFS-based shortest-distance function between two users on a connection graph. Now imagine this runs in production on a graph with hundreds of millions of nodes. How do you design and optimize it?

System DesignAlgorithms & Data StructuresTechnical Trade-offs
Author's notes

This one sprawled in every direction.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by acknowledging the scale challenge and the need for a distributed approach. Then outline a multi-layered strategy: precomputation, graph partitioning, bidirectional search, and caching. Finally, discuss trade-offs between accuracy, latency, and cost, and how to monitor and iterate.

Pro tip: Emphasize that at LinkedIn's scale, you can't run BFS on the full graph in real-time; instead, you'd precompute distances up to a certain degree and use approximations for longer paths. Also, mention that the 'shortest path' might not be the most relevant metric—consider weighted edges based on interaction strength.

1. Clarify Requirements and Constraints

Ask about expected latency, accuracy requirements, graph update frequency, and available resources. This determines whether you need exact or approximate results.

2. Precomputation and Indexing

Precompute distances up to a certain degree (e.g., 3-4 hops) for all pairs or use landmarks. Store results in a distributed key-value store for fast lookup.

3. Graph Partitioning and Distributed BFS

Partition the graph across machines (e.g., by user ID ranges or communities) and run BFS in parallel, using message passing or a Pregel-like system. Use bidirectional BFS to reduce search space.

4. Caching and Approximation

Cache frequent queries and use approximate algorithms (e.g., landmark-based or sketch-based) for longer distances. Consider early termination when a path is found.

5. Monitoring and Iteration

Instrument latency, hit rates, and accuracy. Continuously optimize based on real usage patterns and adjust precomputation depth.

Key Points to Mention

  • Bidirectional BFS to reduce search space from O(b^d) to O(b^(d/2))
  • Graph partitioning strategies (e.g., by geography, community, or hash) and their impact on cross-partition queries
  • Precomputation of distances up to k hops and storage in a distributed cache like Redis or memcached
  • Approximate shortest path algorithms (e.g., landmark-based, sketches) for scalability
  • Caching strategies (LRU, TTL) and handling cache invalidation on graph updates
  • Trade-offs between exactness, latency, and computational cost; use of weighted edges for relevance

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.