Bird
Raised Fist0

Instagram - Photo Upload, Feed, Stories, Explore

HLDhardInterview freq: high
Choose your preparation mode4 modes available
▶
Request Trace
Step 1/5
API Gateway

Receive photo upload request

API Gateway authenticates user and forwards upload to Upload Service

Protocol:HTTPS POST
BeforeUser has photo ready to upload on client device
AfterUpload Service receives authenticated upload request
Upload Service

Store photo in Media Storage

Upload Service uploads photo to S3 and triggers event notification

Protocol:PUT Object + Kafka Event
BeforeUpload Service has photo bytes from API Gateway
AfterPhoto stored durably in S3; event emitted for downstream processing
Feed Generation Service

Consume upload event and generate feed entries

Feed Service writes new feed items referencing photo to Cassandra

Protocol:Kafka Consumer + Cassandra Write
BeforeFeed Service awaits new upload events
AfterFeed entries created in Cassandra for user and followers
Stories Service

Update stories metadata for new content

Stories Service receives notification and writes ephemeral metadata

Protocol:Internal RPC
BeforeStories Service has no record of new photo
AfterStories metadata updated to include new photo story
Explore Service

Index photo for discovery

Explore Service indexes photo metadata for recommendation algorithms

Protocol:Internal RPC
BeforeExplore Service unaware of new photo content
AfterPhoto indexed and available for explore feed queries
🏗️
Architecture Diagram
Architecture Diagram
┌───────────────┐
│ API Gateway   │
└───────┬───────┘
        │ HTTPS POST /upload
        ▼
┌───────────────┐
│ Upload Svc    │
└───────┬───────┘
        │ PUT Object
        ▼
┌─────────────────────────────┐
│ Media Storage (S3 + CDN)    │
└───────┬─────────────────────┘
        │ Event Notification (Kafka)
        ▼
┌─────────────────────────────┐
│ Feed Generation Svc         │
└───────┬───────┬─────────────┘
        │       │
        │       │ Write feed entries
        │       ▼
        │  ┌───────────────┐
        │  │ NoSQL DB      │
        │  │ (Cassandra)   │
        │  └───────────────┘
        │
        │ Notify Stories & Explore
        ▼
┌─────────────────────────────┐
│ Stories Service             │
└───────┬─────────────────────┘
        │ Write stories metadata
        ▼
┌─────────────────────────────┐
│ Explore Service             │
└─────────────────────────────┘

This architecture diagram illustrates Instagram's photo upload flow. The user sends a photo upload request to the API Gateway, which authenticates and forwards it to the Upload Service. The Upload Service stores the photo in durable Media Storage (S3 + CDN) and emits an event. The Feed Generation Service consumes this event to create feed entries in Cassandra for the user and followers. Simultaneously, the Stories Service updates ephemeral story metadata, and the Explore Service indexes the photo for discovery. This vertical flow ensures separation of concerns, scalability, and eventual consistency across feed, stories, and explore features.

Primary Focus

✓

Practice

(1/5)
1. In the message delivery trace, at Step 4 the Delivery Worker checks the recipient's presence TTL in Redis. What happens if the TTL has expired?
easy
A. Delivery Worker immediately marks message as delivered without sending
B. Delivery Worker retries presence check indefinitely until TTL refreshes
C. Delivery Worker deletes the message assuming recipient is offline permanently
D. Delivery Worker queues message for offline delivery and marks as sent but not delivered

Solution

  1. Step 1: Trace Delivery Worker decision at Step 4 -- Bob's presence TTL

    If TTL expired, recipient is considered offline; message cannot be delivered immediately.
  2. Step 2: Check Delivery Worker behavior on expired TTL

    Delivery Worker deletes message from active queue to avoid indefinite retries; offline delivery handled elsewhere.
  3. Final Answer:

    Option C -> Option C
  4. Quick Check:

    Expired presence TTL -> message deleted from active delivery queue [check]
Hint: Expired presence TTL means no immediate delivery, message dropped [OK]
Common Mistakes:
2. For the For-You feed algorithm, which architecture best balances freshness of recommendations with scalability when serving millions of users?
medium
A. Use a monolithic service that recomputes recommendations synchronously on every user request
B. Use a client-side recommendation engine to reduce server load
C. Use an offline batch job to precompute recommendations periodically and serve from cache
D. Use a real-time streaming pipeline to update recommendations instantly per user action

Solution

  1. Step 1: Evaluate synchronous recomputation

    Monolithic synchronous (A) causes high latency and poor scalability.
  2. Step 2: Compare batch vs streaming

    Streaming (C) offers freshness but is complex and costly at scale; client-side (D) lacks data for quality recommendations.
  3. Step 3: Select batch precompute

    Batch jobs (B) balance freshness and scalability by precomputing and caching recommendations.
  4. Final Answer:

    Option C -> Option C
  5. Quick Check:

    Batch precompute caches recommendations for scalable freshness [check]
Hint: Batch precompute balances freshness and scale best [OK]
Common Mistakes:
3. A company must expose internal web services securely to external clients while hiding internal server details and enabling SSL termination. Which proxy architecture is best suited for this?
medium
A. Use a reverse proxy to terminate SSL and hide internal server details
B. Use a transparent proxy to intercept and forward requests without modification
C. Use a forward proxy to route external client requests to internal servers
D. Use a DNS proxy to resolve internal server names for external clients

Solution

  1. Step 1: Identify proxy role for exposing internal services

    A reverse proxy sits in front of internal servers, hides their details, and can terminate SSL for external clients.
  2. Step 2: Eliminate other options

    Forward proxies act on clients, not servers; transparent proxies don't modify requests; DNS proxies only resolve names, not handle SSL or hide servers.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Reverse proxy hides servers and terminates SSL [check]
Hint: Reverse proxy hides servers and handles SSL termination [check]
Common Mistakes:
4. For an API serving millions of users with varying traffic patterns, which rate limiting strategy best balances fairness and system protection?
medium
A. Use a global fixed window counter resetting every minute for all clients
B. Use a simple fixed quota per client without burst allowance
C. Use a token bucket algorithm per client to allow bursty traffic within limits
D. Use a leaky bucket algorithm globally to smooth all incoming requests

Solution

  1. Step 1: Evaluate fixed window and global approaches

    Global fixed window (A) causes unfairness and synchronized spikes; global leaky bucket (D) smooths but penalizes all clients equally.
  2. Step 2: Compare per-client token bucket vs fixed quota

    Fixed quota (C) disallows bursts, hurting user experience; token bucket (B) allows bursts while enforcing long-term limits, balancing fairness and protection.
  3. Final Answer:

    Option C -> Option C
  4. Quick Check:

    Token bucket per client allows controlled bursts [check]
Hint: Token bucket per client balances bursts and fairness [check]
Common Mistakes:
5. At 10x scale, which component is most likely to become the bottleneck first when handling millions of concurrent video streams and progress updates, and why?
hard
A. The relational database storing user progress, due to write contention on user records
B. The WebSocket servers maintaining live connections, due to stateful connection limits
C. The Progress Worker service, due to single-threaded processing of progress update events
D. The CDN edge servers, due to bandwidth limits serving video content globally

Solution

  1. Step 1: Analyze stateful connection scaling

    WebSocket servers maintain stateful connections per user, limiting horizontal scaling due to connection affinity.
  2. Step 2: Compare other components' scalability

    Relational DB (The relational database storing user progress, due to write contention on user records) can be sharded; CDN (The CDN edge servers, due to bandwidth limits serving video content globally) scales horizontally; Progress Worker (The Progress Worker service, due to single-threaded processing of progress update events) can be parallelized.
  3. Final Answer:

    Option B -> Option B
  4. Quick Check:

    WebSocket servers hit stateful connection limits first [check]
Hint: Stateful WebSocket servers limit scaling first [OK]
Common Mistakes:
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard