← Openai Interview Insights

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

Senior
Apr 2026

Summary

Got a system design coding question for a software engineer role at OpenAI. The problem was a versioned social follow graph with friend recommendations, basically build the whole thing in memory from scratch. Pretty involved for a single session.

Questions Asked (1)

Q1

Design and implement an in-memory versioned social follow graph that supports follow/unfollow mutations with timestamps, point-in-time relationship queries, and a scored friend recommendation system based on mutual followees.

System DesignAlgorithms & Data StructuresData Modeling
Author's notes

This one has a lot of moving parts.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying requirements and scale, then design a data model that supports versioning and efficient point-in-time queries. Propose a layered architecture: a core graph store with temporal indexing, a query engine for time-travel, and a recommendation service that computes mutual followees with scoring. Discuss trade-offs and optimizations, and outline an implementation plan with key algorithms.

Pro tip: Emphasize that versioning can be achieved by storing edges with validity intervals (valid_from, valid_to) rather than full snapshots, which saves space and simplifies point-in-time queries. Also, mention that recommendation scoring can be done efficiently using a min-heap or approximate algorithms for large-scale graphs.

1. Clarify Requirements and Scale

Ask about expected number of users, average follows per user, query patterns (point-in-time frequency, recommendation latency), and consistency requirements. This informs data structure and algorithm choices.

2. Design Data Model with Versioning

Propose storing follow edges with timestamps and validity intervals. For each edge (follower, followee), store valid_from and valid_to (null if active). Use an index on (follower, valid_from) and (followee, valid_from) for efficient queries.

3. Implement Point-in-Time Queries

For a query at time T, retrieve edges where valid_from <= T and (valid_to > T or valid_to is null). Use binary search on sorted lists or interval trees for efficiency. Discuss how to handle unfollows by updating valid_to.

4. Design Recommendation System

Compute mutual followees: for a user U, find candidates who are followed by people U follows. Score candidates by number of mutual followees, possibly weighted by recency or other factors. Use efficient set intersections and a priority queue to get top-K.

5. Discuss Optimizations and Trade-offs

Mention caching, sharding, and approximate algorithms for scale. Compare interval-based versioning vs. snapshotting. Discuss consistency vs. availability for distributed settings.

Key Points to Mention

  • Temporal data modeling with validity intervals (valid_from, valid_to) for edges
  • Efficient point-in-time query using binary search or interval trees
  • Indexing strategies: composite indexes on (follower, valid_from) and (followee, valid_from)
  • Mutual followee computation via set intersection of followees' followees
  • Scoring and ranking recommendations using a min-heap for top-K
  • Trade-offs: memory vs. query speed, exact vs. approximate recommendations, consistency models

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