← Openai Interview Insights

Openai·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
May 2026

Summary

OpenAI software engineer coding round, one question about a social network system. Nothing too wild but I definitely hadn't drilled this one beforehand and had to figure it out live.

Questions Asked (1)

Q1

Design a social network with follow/unfollow functionality and a feature to recommend up to K friend-of-friend connections.

Algorithms & Data StructuresSystem Design
Author's notes

Had seen this floating around before and never actually sat down to work through it.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying requirements and scale, then design a graph-based data model with efficient follow/unfollow operations. For friend-of-friend recommendations, use a breadth-first search up to depth 2, aggregating mutual connections and ranking by count, while addressing scalability with sharding and caching.

Pro tip: Emphasize trade-offs between different approaches (e.g., BFS vs. precomputed recommendations) and discuss how to handle large-scale graphs with partitioning and asynchronous updates. Mention that recommendations can be computed offline and served via a fast lookup service.

1. Clarify Requirements and Scale

Ask about expected number of users, average connections, read/write ratio, latency requirements, and whether recommendations need to be real-time or can be batch-computed.

2. Design Data Model and Storage

Propose a graph representation: users as nodes, follows as directed edges. Use a distributed database like Cassandra or a graph DB (e.g., Neo4j) for storage, with adjacency lists for efficient traversal.

3. Implement Follow/Unfollow

Describe how to add/remove edges: update the follower's following list and the followee's followers list. Discuss consistency, idempotency, and handling high write throughput.

4. Recommend Friend-of-Friend Connections

Explain BFS from the user up to depth 2 to find candidates, then rank by number of mutual friends. For scalability, consider precomputing recommendations offline using MapReduce or graph processing frameworks.

5. Address Scalability and Performance

Discuss sharding by user ID, caching frequent recommendations, using approximate algorithms for large graphs, and ensuring low-latency reads via denormalization.

Key Points to Mention

  • Graph data model with adjacency lists for efficient traversal
  • Breadth-first search (BFS) for friend-of-friend discovery, with depth limit 2
  • Ranking recommendations by number of mutual connections
  • Trade-offs between real-time computation and precomputed (offline) recommendations
  • Scalability techniques: sharding, caching, asynchronous updates
  • Handling follow/unfollow with idempotent operations and eventual consistency

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