Api Design medium
A client fetches /products/123 and receives ETag: 'abc123'. How does the client use this for conditional caching?
- A Send the If-None-Match header with the last seen ETag value; the server then validates the version and returns a 304 Not Modified if the data is identical.
- B Cache the ETag value in the browser's local storage and append it as a query parameter in every subsequent request to ensure the server skips data rendering.
- C Use the ETag as a unique transaction identifier in the request body to prevent duplicate submissions and ensure strictly atomic rate limiting operations.
- D Provide the ETag in a custom X-Cache-Key header so that intermediate CDN nodes can bypass the origin server and serve the response from the edge.
Answer: A. Send the If-None-Match header with the last seen ETag value; the server then validates the version and returns a 304 Not Modified if the data is identical.
**ETags** (Entity Tags) allow for conditional requests. When a client makes a subsequent request for a resource, it sends the `If-None-Match: <etag>` header. If the resource hasn't changed on the server, the server returns **304 Not Modified** with no body, saving bandwidth and processing time. The client then uses its locally cached version.
One system design question a day, with spaced repetition so the ones you miss come back.
Get the appRelated questions
- You're designing a REST API for a blog. Which endpoint best represents 'get all comments for post 123'?
- A client wants to update only the 'status' field of an order, leaving other fields unchanged. Which HTTP method is most appropriate?
- A client calls POST /users with valid data, and the user is created. What status code should the server return?
- A client retries a failed 'POST /payments' request due to network timeout. The server receives the request twice. Without idempotency handling, what can happen?
- An API returns 10,000 products. Returning all in one response is impractical. Which pagination approach is simple and stateless?
- Your API serves both mobile apps and third-party integrations. Which authentication method is most appropriate?