Free preview

High-Level Design: Frontend and Metadata Service

Why this matters: the frontend is where every request is validated, authenticated, and deduplicated, and the metadata service is what turns a queue name into a physical host. Neither stores a single message, and both are essential.

Key takeaway

Unlike a single-server queue, a distributed queue runs across multiple servers. That adds operational complexity but addresses the scalability and fault-tolerance limitations of a single-node design.

Two assumptions

AssumptionDetail
ReplicationQueue data is replicated within a cluster using primary-secondary or quorum-like systems. If a queue exceeds single-server capacity, use data partitioning — via consistent hashing, or a key-value store with message sequence numbers as keys. Each shard is then replicated
ElasticityThe system automatically scales resources in response to demand

The architecture

Load balancer

The load balancer layer distributes requests from producers and consumers to frontend servers. This minimizes latency and ensures high availability.

Frontend service

Stateless machines distributed across data centers, performing six functions:

FunctionWhat it does
Request validationVerifies that requests contain all necessary information
Authentication and authorizationConfirms user identity and permissions
CachingStores metadata for frequently accessed queues and user data to reduce latency
Request dispatchingRoutes calls to the backend or metadata store
Request deduplicationPrevents identical requests from entering the queue. It checks a hash key store; if a duplicate is found, the request is rejected
Usage data collectionAggregates real-time data for auditing

Metadata service

Manages queue metadata in the metadata store and cache. It updates both whenever a queue is created or deleted. Acting as middleware between frontend servers and the data layer, it prioritizes cache lookups; on a cache miss it retrieves from the store and updates the cache.

Organizing the metadata cluster

Two approaches, depending on whether the metadata fits on one machine.

1. Small metadata

If it fits on a single machine, replicate it across all cluster servers. Requests can be served by any server, and a load balancer can sit between frontend servers and metadata services.

2. Large metadata

If metadata is too large for a single machine, shard it. Two strategies:

StrategyWhere the mapping table livesBehaviorSuits
Frontend mappingOn the frontend serversData is sharded by partition key or hash; each shard sits on a specific host and is replicated for availability. The frontend routes requests to the correct hostRouting decided before the request leaves the frontend — one network hop
Host-based mappingOn each metadata hostAny host can receive a request and forward it to the correct data nodeRead-intensive applications

Key takeaway

A stateless frontend does validation, auth, dedup, and dispatch; the metadata service translates queue identity into physical location, backed by read-through cache and write-through updates. As metadata outgrows one machine, you choose between frontend mapping (fast, harder to keep in sync) and host-based mapping (an extra hop, one place to update).

Interview signal by level

LevelWhat a strong answer sounds like
L4"A load balancer in front of some servers that hold the queues."
L5Separates the tiers: "stateless frontends handle validation, auth, and dedup; a metadata service maps a queue to the host that owns it, cached to keep the lookup cheap."
Staff+Distinguishes the two dedup guarantees and the mapping trade: "frontend dedup stops the same message being enqueued twice; it does not give exactly-once, because the duplicate that matters happens after enqueue when a consumer dies before acking. And once metadata outgrows a machine, frontend mapping is one hop but every frontend must agree on the shard map — host-based is two hops with one place to update. Same trade as the cache client."

Next: where the messages actually live.

Enjoying the preview?

Create a free account to unlock the rest of this course, the in-browser judge, and live AI mock interviews.

Sign up free to continue