Bird
Raised Fist0

API Versioning Strategies - URL, Header, Content Negotiation

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

Sends HTTP request with API version in URL path, header, or Accept header

Client includes version info as /v2/resource, X-API-Version: 2, or Accept: application/vnd.api.v2+json

Protocol:HTTP/1.1
BeforeClient has constructed request with version info in URL or headers
AfterRequest is sent over network to API Gateway
API Gateway (Nginx + Envoy Proxy)

Receives request and forwards to Version Routing Service

Gateway terminates client connection, inspects request, and proxies it

Protocol:HTTP/1.1 or HTTP/2
BeforeRequest arrived at gateway with version info intact
AfterRequest forwarded to Version Routing Service preserving headers
Version Routing Service (Envoy Filter + Custom Router)

Parses version info and routes request to correct microservice version

Uses Envoy filter to extract version from URL, header, or Accept header and selects backend

Protocol:gRPC or HTTP/REST
BeforeRequest received with version info in headers or URL
AfterRequest routed to Microservice instance matching requested API version
Microservices per API Version

Processes request according to API version logic and returns response

Microservice executes business logic for the specific API version

Protocol:gRPC or HTTP/REST
BeforeRequest received by correct versioned microservice
AfterResponse generated and sent back upstream
Monitoring & Logging System (Elastic Stack + Prometheus)

Collects metrics and logs from API Gateway and Microservices

Metrics include request counts, latencies, and error rates per API version

Protocol:HTTP/REST or Push
BeforeServices running with monitoring enabled
AfterMetrics and logs stored for observability and alerting
Configuration Management (Consul + GitOps)

Provides routing configuration and version metadata to Version Routing Service

Updates routing rules dynamically via Consul and GitOps pipelines

Protocol:HTTP/REST or gRPC
BeforeRouting configs may be outdated or stale
AfterVersion Routing Service has updated configs for accurate routing
🏗️
Architecture Diagram
Architecture Diagram
┌─────────┐
│ Client  │
└────┬────┘
     │ HTTP Request (URL, Header, Accept)
     ▼
┌───────────────────────────────┐
│ API Gateway                   │
│ (Nginx + Envoy Proxy)         │
└─────────────┬─────────────────┘
              │ HTTP/1.1 or HTTP/2
              ▼
┌────────────────────────────────────────┐
│ Version Routing Svc                    │
│ (Envoy Filter + Custom Router)         │
└─────────────┬─────────────────────────┘
              │ gRPC or HTTP/REST
              ▼
┌───────────────────────────────┐
│ Microservices per API Version  │
│ (v1, v2, v3...)                │
└─────────────┬─────────────────┘
              │ Metrics & Logs
              ▼
┌────────────────────────────────────────┐
│ Monitoring & Logging Sys                │
│ (Elastic Stack + Prometheus)            │
└────────────────────────────────────────┘
              ▲
              │ Configuration Updates
┌────────────────────────────────────────┐
│ Config Management                      │
│ (Consul + GitOps)                      │
└────────────────────────────────────────┘

This architecture demonstrates how API versioning is handled using three common strategies: URL path, custom headers, and content negotiation via Accept headers. The Client sends requests with version info embedded in one of these ways. The API Gateway (Nginx + Envoy Proxy) acts as the entry point, forwarding requests to the Version Routing Service. This service uses Envoy filters and custom routing logic to parse the version and route the request to the appropriate Microservice instance implementing that API version. Observability is ensured by the Monitoring & Logging System collecting metrics and logs from the gateway and microservices. Configuration Management via Consul and GitOps pipelines dynamically updates routing rules, enabling flexible version rollout and deprecation. This vertical flow ensures clear separation of concerns and supports multiple versioning strategies simultaneously.

Primary Focus

✓

Practice

(1/5)
1. In a CDN cache invalidation flow, at step 4 the surrogate key invalidation service receives a purge request for a surrogate key. What does it do next?
easy
A. Publishes an asynchronous invalidation message to edge caches to purge objects with that surrogate key
B. Marks the surrogate key as expired but leaves cached objects until TTL expires
C. Updates TTL values on cached objects with that surrogate key to zero
D. Immediately deletes all cached objects with that surrogate key from all edge caches synchronously

Solution

  1. Step 1: Understand surrogate key purge semantics

    Surrogate key invalidation marks keys as expired; actual cache purge happens lazily or on next request.
  2. Step 2: Eliminate immediate deletion and TTL update

    Immediate synchronous deletion is costly and rare; TTL update is not typical surrogate key behavior; asynchronous invalidation is plausible but surrogate keys usually mark expired state.
  3. Final Answer:

    Option B -> Option B
  4. Quick Check:

    Surrogate keys mark expired, actual purge deferred [check]
Hint: Surrogate keys mark expired, don't instantly delete cache [check]
Common Mistakes:
2. In a composite index on columns (A, B), a query filters only on column B. At step 3 in the query execution plan, the database engine uses the composite index. What is the state of index usage at this step?
easy
A. The composite index cannot be used efficiently because column A is not filtered, causing a full index scan
B. The composite index is fully used to seek on column B alone efficiently
C. The database ignores the composite index and uses a table scan instead
D. The composite index is partially used by scanning leaf nodes but with poor performance

Solution

  1. Step 1: Understand composite index column order

    Composite indexes are ordered by the first column (A), then second (B). Queries filtering only on B cannot efficiently seek the index without filtering on A.
  2. Step 2: Analyze index usage at step 3

    Since column A is not filtered, the engine must scan the entire index or large portions, resulting in a full index scan rather than an efficient seek.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Composite index requires leading column filter for efficient seeks [check]
Hint: Composite index needs leading column filter for seeks [check]
Common Mistakes:
3. If the Kafka cluster responsible for vote event streaming goes down, what exactly breaks in the Reddit voting system?
medium
A. Vote events cannot be buffered, causing vote submission requests to block or fail immediately
B. The UI shows stale post scores but votes are queued in Redis for later processing
C. Votes continue to be processed but ranking updates become inconsistent
D. Users can still vote, but votes are lost silently without any retry

Solution

  1. Step 1: Understand Kafka's role in buffering vote events

    Kafka buffers vote events reliably; if it fails, vote events cannot be streamed to processors.
  2. Step 2: Analyze failure impact

    Vote submissions do not block immediately (Vote events cannot be buffered, causing vote submission requests to block or fail immediately wrong) because frontends can still accept votes and cache temporarily. Votes are not lost silently (Users can still vote, but votes are lost silently without any retry wrong) because Redis or other caches buffer them. UI shows stale scores due to lack of processed updates (The UI shows stale post scores but votes are queued in Redis for later processing correct). Votes continue to be processed but ranking updates become inconsistent is incorrect as votes stop flowing, not just ranking inconsistency.
  3. Final Answer:

    Option B -> Option B
  4. Quick Check:

    Kafka failure causes stale UI scores; votes buffered in Redis [check]
Hint: Kafka down -> stale UI, votes buffered temporarily [check]
Common Mistakes:
4. If the GeoDNS service loses its health check integration with data centers, what exact failure occurs when a data center goes down?
medium
A. GeoDNS stops responding to DNS queries, causing total outage
B. GeoDNS caches old IPs indefinitely, causing stale routing for weeks
C. GeoDNS continues to resolve to the down data center, causing user requests to fail
D. GeoDNS automatically reroutes traffic to the next closest data center without delay

Solution

  1. Step 1: Understand health check role

    Health checks inform GeoDNS about data center availability to avoid routing to down centers.
  2. Step 2: Analyze failure impact

    Without health checks, GeoDNS cannot detect down data centers, so it may continue routing to them (B). However, many GeoDNS implementations fallback to rerouting to next closest center (C) based on stale or fallback data.
  3. Final Answer:

    Option D -> Option D
  4. Quick Check:

    GeoDNS reroutes to next closest center despite missing health checks [check]
Hint: Without health checks, GeoDNS reroutes to next closest center [check]
Common Mistakes:
5. At 10x scale, which Pastebin component is most likely to fail first and why?
hard
A. The relational database, because complex joins for analytics become a bottleneck
B. The analytics event ingestion pipeline, because Kafka partitions saturate and cause backpressure
C. The Expiration Worker, because scanning all snippets for TTL expiry becomes too slow
D. The snippet storage layer, because key-value stores cannot shard keys efficiently at scale

Solution

  1. Step 1: Analyze scaling bottlenecks

    Expiration Worker scans all snippets to delete expired ones; at 10x scale, scan latency grows linearly.
  2. Step 2: Compare other components

    Relational DB (A) is not primary storage; key-value stores (C) shard well; Kafka (D) scales with partitioning but expiration scanning is a linear bottleneck.
  3. Final Answer:

    Option C -> Option C
  4. Quick Check:

    Expiration scanning is linear and slows down first at scale [check]
Hint: Expiration scanning scales linearly, fails first at 10x [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