Design Instagram/Twitter News Feed

Medium

Functional Requirements (FRs)

  • Users should be able to publish text posts.
  • Users should be able to follow each other.
  • Users should be able to go to anyone's profile (including their own) and see their posts.
  • Users should be able to see their news feed based on posts created by people they are following.
  • The news feed should be sorted in reverse chronological order.

Non-Functional Requirements (NFRs)

  • Daily-active users (DAU): 1B.
  • Max followers a user can have: 100M.
  • Max people a user can follow: 10000.
  • Posts created per day: 1x of DAU.
  • Feed loads per day: 10x of DAU.
  • Max Post Length: 10000 characters.
  • The feed can be stale by at most 5-10s.
  • The feed load should be very fast.

How to solve the problem?

  • General:
    • Note everything you are discussing or thinking of in the text editor.
    • Draw everything that your interviewer needs to visualize on the whiteboard.
    • Be cognizant of how much time you've left and pace yourself (as required) so as to cover things that the interviewer wants to see you do based on the FRs and NFRs that were finalized.
  • Step 1: Think about the functional and non-functional requirements.
    • In an interview, the FRs and NFRs won't be provided.
    • You need to have a discussion with your interviewer to finalize these.
    • This step should take around 10-15 mins.
  • Step 2: For senior developers:
    • Note down the metric estimations.
    • The metrics would generally include read and write QPS, latency, storage, memory, bandwidth, etc.
  • Step 3: (Optional) Note down the APIs that you would need to support the functional requirements. Do it only if you've time.
  • Step 4: High-level design:
    • Propose and draw a very high-level design.
    • This design might have flaws and bottlenecks.
    • This design should just give a very high-level idea of the overall system.
  • Step 5: Deep-dive into the design:
    • Come up with the bottlenecks in the initial design and iteratively come up with a better design addressing the bottlenecks and trade-offs.
    • Update the design on the whiteboard as you are solving the bottlenecks.
    • Try to come up with multiple solutions for certain bottlenecks and mention the trade-offs and the reasons why you are picking up one over the others. If you don't have time, just mention them but don't note them.
    • If the interviewer asks, mention the DB schema as well. While practicing, make sure to add the DB schema.
  • Step 6: Overview:
    • Try to give an overview of the entire design specifically talking about the major decisions taken.
Creators
Gaurav
Gaurav Chandak
Setter