Api Design medium
A mobile app fetches user profile AND settings in two separate calls on every screen load. How can the API reduce latency?
- A Design a composite endpoint such as GET /users/123/profile-with-settings that aggregates multiple resource representations into a single response body.
- B Enable HTTP/1.1 Keep-Alive and request pipelining to allow the client to send multiple requests over a single connection without waiting for responses.
- C Advise the client application to implement a local SQLite database for aggressive caching, reducing the need for network calls during repetitive screen loads.
- D Upgrade the server's compute resources and network interface bandwidth to minimize the individual processing time for each separate API request.
Answer: A. Design a composite endpoint such as GET /users/123/profile-with-settings that aggregates multiple resource representations into a single response body.
Latency is often dominated by network round trips (RTT). **Composite endpoints** (like `GET /users/123/full`) allow the client to fetch multiple related resources (profile, settings, preferences) in a single request, eliminating the overhead of establishing multiple connections/requests. GraphQL solves this generically, but composite endpoints are a common REST pattern.
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?