Api Gateway medium
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?
- A By automatically blocking all POST requests that take longer than 500ms to process.
- B By enforcing a strict 'One Request Per Day' rule for every user.
- C By implementing an 'Idempotency Key' check: If the Gateway receives the same unique key it just successfully processed, it returns the cached result without calling the Payment Service again.
- D By using a special algorithm that detects duplicate clicks on a touch screen.
Answer: C. By implementing an 'Idempotency Key' check: If the Gateway receives the same unique key it just successfully processed, it returns the cached result without calling the Payment Service again.
Idempotency is critical for distributed systems. If a client sends a 'Pay $50' request and the network drops before they see the 'Success' message, they will retry. The Gateway uses a client-provided `X-Idempotency-Key` to ensure the expensive backend operation only happens exactly once.
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?
- What is the primary operational benefit of performing 'SSL Termination' at the API Gateway?