Bird
Raised Fist0

UUID vs Auto-Increment vs Custom ID - Trade-offs at Scale

HLDmediumInterview freq: common
Choose your preparation mode4 modes available
▶
Request Trace
Step 1/8
Client Applications

Send ID generation request

Client requests a new unique ID for a record

Protocol:HTTP REST
BeforeClient has a new record needing a unique ID
AfterRequest sent to ID Generation Layer
ID Generation Layer

Check Cache for recent IDs

Lookup ID in Cache Layer to avoid DB hit

Protocol:Redis GET
BeforeID Generation Layer has request but no cached ID
AfterCache hit or miss determined
Cache Layer

Return cached ID or miss

Returns cached ID if available, else miss

Protocol:Redis Response
BeforeCache contains recent IDs or is empty for this key
AfterID Generation Layer knows if cache hit or miss
ID Generation Layer

Generate or retrieve ID

If cache miss, generate ID (UUID/AutoInc/Custom) and write to DB

Protocol:DB Insert
BeforeNo cached ID found for request
AfterNew ID generated and persisted in DB
Distributed Database

Persist new ID record

Insert new record with generated ID ensuring durability

Protocol:Write-Ahead Log + Replication
BeforeDB does not have the new ID record
AfterNew ID record durably stored in DB
Cache Layer

Update cache with new ID

Cache Layer stores new ID for future quick retrieval

Protocol:Redis SET
BeforeCache does not have the new ID
AfterCache updated with new ID
ID Generation Layer

Return generated ID to client

Responds with the new unique ID

Protocol:HTTP Response
BeforeID generated and stored
AfterClient receives unique ID
Monitoring and Alerting

Record metrics and alert on anomalies

Monitors ID generation latency, errors, and throughput

Protocol:Metrics Export
BeforeSystem running normally
AfterMetrics updated, alerts triggered if thresholds breached
🏗️
Architecture Diagram
Architecture Diagram
┌───────────────────────┐
│   Client Applications │
└─────────────┬─────────┘
              │ HTTP Request (REST/GRPC)
              ▼
┌───────────────────────┐
│   ID Generation Layer │
│  (UUID, AutoInc, CID) │
└─────────────┬─────────┘
              │ Cache Lookup (Redis GET)
              ▼
┌───────────────────────┐
│      Cache Layer      │
│  (Redis/Memcached)    │
└─────────────┬─────────┘
              │ Cache Miss or Hit
              ▼
┌─────────────────────────┐
│ Distributed Database    │
│  (Cassandra, Spanner)   │
└─────────────┬───────────┘
              │ DB Write (Insert ID)
              ▼
┌───────────────────────┐
│ Monitoring and Alerting│
│  (Prometheus, Grafana) │
└───────────────────────┘

This architecture illustrates the trade-offs in ID generation at scale. Client Applications request unique IDs via the ID Generation Layer, which first checks the Cache Layer to reduce load on the Distributed Database. If the ID is not cached, the layer generates a new ID using UUID, Auto-Increment, or Custom logic and persists it in the database to ensure durability. The Cache Layer is then updated to speed up future requests. Monitoring and Alerting continuously track system health and performance metrics. This design balances latency, scalability, and consistency, highlighting how caching and database choice impact ID generation strategies.

Primary Focus

✓

Practice

(1/5)
1. In a system designed for 99.999% availability, at step 4 the Delivery Worker checks the message queue for pending retries. What happens if the message is not acknowledged by the consumer within the visibility timeout?
easy
A. The message is archived permanently without retry
B. The message is deleted immediately to prevent duplicates
C. The message becomes visible again for redelivery to another consumer
D. The Delivery Worker blocks until the consumer acknowledges

Solution

  1. Step 1: Trace Delivery Worker decision at Step 4 -- message visibility timeout

    If the message is not acknowledged within the visibility timeout, it becomes visible again for redelivery to ensure no message loss.
  2. Step 2: Eliminate incorrect options

    Immediate deletion (A) risks message loss; archiving without retry (C) breaks availability; blocking (D) reduces throughput and availability.
  3. Final Answer:

    Option C -> Option C
  4. Quick Check:

    Visibility timeout expiry -> message re-queued for retry [check]
Hint: Visibility timeout expiry -> message re-queued for retry [check]
Common Mistakes:
2. In the request flow of the fraud detection system, at step 4 the Real-Time Scoring component queries the Feature Store. What happens if the Feature Store returns stale data due to eventual consistency?
easy
A. The scoring component uses the stale features, potentially causing inaccurate fraud scores
B. The scoring component retries the query immediately, causing increased latency
C. The scoring component blocks until fresh data arrives, delaying the transaction
D. The scoring component falls back to default feature values, ignoring the stale data

Solution

  1. Step 1: Trace scoring behavior on stale data

    The scoring component queries the Feature Store asynchronously; it does not block (A) or retry immediately (C). It uses whatever data is returned.
  2. Step 2: Understand fallback mechanisms

    Fallback to default values (D) is not automatic; stale data is used as-is, which may reduce accuracy but maintains low latency.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Stale features used -> possible inaccurate scores, no blocking [check]
Hint: Real-time scoring uses latest available features, even if stale [check]
Common Mistakes:
3. A global web service must route user requests to the nearest healthy data center with minimal latency and automatic failover. Which component is best suited to handle this requirement?
easy
A. Deploy a Global Server Load Balancer (GSLB) that monitors data center health and routes accordingly
B. Configure client-side logic to select the closest data center IP address
C. Use DNS-based load balancing with low TTL values to direct traffic
D. Rely on BGP routing policies to steer traffic to preferred data centers

Solution

  1. Step 1: Identify component for global health-aware routing

    DNS with low TTL (Use DNS-based load balancing with low TTL values to direct traffic) can cause caching issues and slow failover; client-side logic (Configure client-side logic to select the closest data center IP address) is unreliable and hard to maintain; BGP routing (Rely on BGP routing policies to steer traffic to preferred data centers) is coarse-grained and slow to converge.
  2. Step 2: Understand GSLB capabilities

    GSLB actively monitors data center health and latency, dynamically routing users to the best endpoint, providing low latency and automatic failover.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    GSLB monitors health and routes globally with failover [check]
Hint: GSLB actively monitors and routes globally [check]
Common Mistakes:
4. At 10x scale, which component in the web crawler system is most likely to become the first bottleneck, and why?
hard
A. URL Frontier, because it cannot shard URLs efficiently leading to queue contention
B. Scheduler, because it cannot prioritize URLs fast enough under high throughput
C. Politeness Policy Manager, because maintaining per-domain timers statefully limits horizontal scaling
D. Duplicate Detection, because its in-memory hash set grows beyond memory capacity causing slow lookups

Solution

  1. Step 1: Identify statefulness of Politeness Policy Manager

    It maintains per-domain timers and request schedules, which are stateful and hard to shard.
  2. Step 2: Compare with other components

    URL Frontier can shard URLs; Duplicate Detection can use scalable storage; Scheduler can be distributed but Politeness Policy requires domain-specific timing.
  3. Final Answer:

    Option C -> Option C
  4. Quick Check:

    Politeness Policy's stateful timers limit scaling first [check]
Hint: Stateful timers in Politeness Policy block scaling first [OK]
Common Mistakes:
5. At 10x scale, which component in Spotify's streaming architecture is most likely to fail first and why?
hard
A. The metadata database due to increased write contention on user playlists
B. The streaming servers because maintaining millions of concurrent WebSocket connections is stateful and hard to shard
C. The CDN edge caches due to limited storage capacity per region
D. The offline download manager due to device storage limits

Solution

  1. Step 1: Identify stateful bottlenecks at scale

    Streaming servers maintain WebSocket connections which are stateful and tied to server memory.
  2. Step 2: Evaluate scaling challenges

    Metadata DB (A) can be sharded; CDN caches (B) scale by adding regions; offline manager (D) limited by device, not server scale. Streaming servers (C) face connection limits and resharding complexity.
  3. Final Answer:

    Option B -> Option B
  4. Quick Check:

    Stateful WebSocket servers fail first at 10x scale [check]
Hint: Stateful WebSocket servers bottleneck at scale [check]
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