Api Gateway easy
How can an API Gateway help protect a slow database during a traffic spike for a static resource (like a 'Product Catalog')?
- A By automatically deleting duplicate products to save space.
- B Via Response Caching: The Gateway stores the successful JSON response in its own memory and serves it directly for subsequent requests, bypassing the microservice and database.
- C By increasing the frequency of full database backups.
- D By forcing the database to use only a single processor core to prevent it from overheating.
Answer: B. Via Response Caching: The Gateway stores the successful JSON response in its own memory and serves it directly for subsequent requests, bypassing the microservice and database.
If 1,000 users all ask for the same 'Product A' price at the same time, the Gateway can ask the Product Service once, cache the answer for 60 seconds, and answer the other 999 users without ever touching the backend again. This drastically improves performance and reduces server costs.
One system design question a day, with spaced repetition so the ones you miss come back.
Get the appRelated questions
- Your Gateway communicates with backends via HTTP/1.1 connections. A slow backend service causes 'Head-of-Line Blocking'. How does switching to HTTP/2 as the Gateway-to-Backend transport mitigate this?
- What is the primary architectural role of an API Gateway in a microservices environment?
- Why is 'Stateless Token Validation' (e.g., using JWTs) significantly more scalable at the Gateway level than 'Stateful Validation' (e.g., using Opaque/Reference Tokens)?
- Your Gateway is configured to cache any URL ending in `.css` or `.jpg`. An attacker tricks a victim into visiting `https://api.com/v1/profile/info/style.css`. How can this lead to an 'Account Takeover'?
- An API is receiving a sudden surge of 10,000 requests per second from a single IP address. How does an API Gateway preserve the stability of the backend services?
- How can an API Gateway help prevent 'Double Charging' in a payment system when a mobile client retries a failed request due to a poor connection?