Bird
Raised Fist0
HLDsystem_design~10 mins

API versioning strategies in HLD - Scalability & System Analysis

Choose your learning style10 modes available
Scalability Analysis - API versioning strategies
Growth Table: API Versioning Strategies
Users / ClientsWhat ChangesVersioning Impact
100 usersFew API calls, low trafficSimple versioning (URI or header) works fine
10,000 usersIncreased API calls, multiple clientsNeed clear versioning to avoid breaking changes; support multiple versions
1,000,000 usersHigh traffic, many client types (mobile, web, partners)Versioning strategy must support backward compatibility and smooth upgrades; automated routing to versions
100,000,000 usersMassive scale, global distributionVersioning combined with API gateways, canary releases, and deprecation policies; caching and CDN to reduce load
First Bottleneck

The first bottleneck is usually the API gateway or routing layer that manages versioning logic.

As traffic grows, routing requests to the correct API version adds latency and CPU load.

Also, maintaining multiple versions increases backend complexity and database schema compatibility.

Scaling Solutions
  • Horizontal scaling: Add more API servers behind load balancers to handle traffic.
  • API Gateway: Use a dedicated gateway to route requests efficiently to correct versions.
  • Caching: Cache common responses per version to reduce backend load.
  • Deprecation policy: Gradually retire old versions to reduce maintenance overhead.
  • Version negotiation: Support flexible versioning via headers or query params to simplify client upgrades.
  • Schema evolution: Design APIs to be backward compatible to minimize version proliferation.
Back-of-Envelope Cost Analysis

Assuming 1 million users making 1 request per second:

  • Requests per second: ~1,000,000 QPS
  • API servers needed: ~200-1000 servers (assuming 1000-5000 QPS per server)
  • Bandwidth: If average response size is 10 KB, total bandwidth ~10 GB/s (~80 Gbps)
  • Storage: Versioned API logs and data may increase storage needs by 10-20%
Interview Tip

Structure your scalability discussion by:

  1. Explaining the versioning strategy (URI, header, query param)
  2. Discussing how multiple versions affect routing and backend complexity
  3. Identifying bottlenecks like API gateway and database schema compatibility
  4. Proposing scaling solutions: horizontal scaling, caching, deprecation
  5. Considering client upgrade paths and backward compatibility
Self Check

Your database handles 1000 QPS. Traffic grows 10x. What do you do first?

Answer: Introduce read replicas and caching to reduce database load before scaling vertically or sharding.

Key Result
API versioning strategies scale by managing routing complexity and backward compatibility; the API gateway is the first bottleneck, solved by horizontal scaling, caching, and deprecation policies.

Practice

(1/5)
1. Which of the following is a common method to implement API versioning?
easy
A. Changing the database schema without notice
B. Including the version number in the URL path
C. Using random query parameters unrelated to version
D. Ignoring backward compatibility

Solution

  1. Step 1: Understand common API versioning methods

    API versioning often uses clear, explicit methods like URL paths, query parameters, or headers to indicate version.
  2. Step 2: Evaluate options for correctness

    Only including the version number in the URL path is a standard, clear method. Other options either break compatibility or are unrelated.
  3. Final Answer:

    Including the version number in the URL path -> Option B
  4. Quick Check:

    Version in URL path = B [OK]
Hint: Version in URL path is the most visible method [OK]
Common Mistakes:
  • Confusing random query parameters with versioning
  • Ignoring backward compatibility importance
  • Assuming database changes equal API versioning
2. Which syntax correctly shows versioning using a query parameter in an API request?
easy
A. GET /api/resource?v=2
B. GET /api/v2/resource
C. GET /api/resource/version2
D. GET /api/resource?version-2

Solution

  1. Step 1: Identify query parameter versioning syntax

    Query parameter versioning appends a key-value pair like ?v=2 to the URL.
  2. Step 2: Compare options for correct query parameter format

    GET /api/resource?v=2 uses ?v=2 which is correct. Others use path or invalid query syntax.
  3. Final Answer:

    GET /api/resource?v=2 -> Option A
  4. Quick Check:

    Query param version = C [OK]
Hint: Query params use ?key=value format [OK]
Common Mistakes:
  • Using path segments instead of query parameters
  • Incorrect query parameter syntax like missing '='
  • Confusing version in path with query versioning
3. Given this API Gateway routing rule: if request.header['API-Version'] == 'v2' then route to service_v2 else route to service_v1, what happens when a request has no API-Version header?
medium
A. Request is rejected with error
B. Request is routed to service_v2
C. Request is routed to service_v1
D. Request is routed randomly

Solution

  1. Step 1: Analyze the routing condition

    The rule routes to service_v2 only if header 'API-Version' equals 'v2'. Otherwise, it routes to service_v1.
  2. Step 2: Determine routing when header is missing

    If the header is missing, condition fails, so request goes to service_v1 by default.
  3. Final Answer:

    Request is routed to service_v1 -> Option C
  4. Quick Check:

    Missing header defaults to v1 routing = A [OK]
Hint: Missing header triggers else branch routing [OK]
Common Mistakes:
  • Assuming missing header routes to v2
  • Thinking missing header causes error
  • Believing routing is random without header
4. A developer implemented API versioning by adding a new version in the URL path but forgot to update the API Gateway routing rules. What is the most likely problem?
medium
A. The old version will be disabled automatically
B. All requests will be routed correctly to the new version
C. API Gateway will automatically detect and route new versions
D. Requests to the new version will fail or go to the old service

Solution

  1. Step 1: Understand API Gateway role in version routing

    API Gateway must be configured to route requests to correct service versions based on URL or headers.
  2. Step 2: Analyze impact of missing routing update

    If routing rules are not updated for new URL version, requests won't reach the new service and may fail or default to old service.
  3. Final Answer:

    Requests to the new version will fail or go to the old service -> Option D
  4. Quick Check:

    Missing routing update causes failures = A [OK]
Hint: Update routing rules with new version URLs [OK]
Common Mistakes:
  • Assuming API Gateway auto-updates routing
  • Believing old version disables automatically
  • Ignoring routing configuration importance
5. You need to design an API that supports multiple versions simultaneously without breaking existing clients. Which strategy best supports this requirement?
hard
A. Use an API Gateway to route requests based on version in headers or URL
B. Change the API contract directly and remove old versions immediately
C. Use only query parameters for versioning and ignore headers
D. Deploy a single service that handles all versions internally without routing

Solution

  1. Step 1: Identify requirements for supporting multiple versions

    Supporting multiple versions simultaneously requires clear routing to different service versions without breaking clients.
  2. Step 2: Evaluate strategies for version management

    Using an API Gateway to route requests based on version in headers or URL cleanly separates versions and maintains backward compatibility.
  3. Step 3: Eliminate less scalable or risky options

    Removing old versions immediately breaks clients; relying only on query parameters limits flexibility; single service handling all versions complicates code and risks errors.
  4. Final Answer:

    Use an API Gateway to route requests based on version in headers or URL -> Option A
  5. Quick Check:

    API Gateway routing supports multiple versions = D [OK]
Hint: API Gateway routing is key for multi-version support [OK]
Common Mistakes:
  • Removing old versions too soon
  • Ignoring header-based versioning
  • Overloading single service with all versions
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