KatInterview

Aggregating Three Upstream Services with Graceful Degradation

System DesignModel answer
MediumModel answerSystem Designapi-designresiliencetimeouts

Last updated

Design a startup endpoint that resolves a user's internal ID, fans out to two dependent services, and still returns useful data when optional services fail or run slowly.

Startup Profile Endpoint

You are building a backend endpoint that a client app calls on launch. It receives a user_id and assembles one response from three existing internal services. You may assume mock versions of these services exist, but their exact wire formats are not specified beyond the fields listed below.

Upstream services

ServiceInputRelevant output
Consumeruser_iduser information, including consumer_id and roles
Paymentconsumer_iddefault card, available gift-card credit
Addressconsumer_idformatted address, first name, last name

Rules

  • user_id and consumer_id are different identifiers. Payment and Address must be called with consumer_id, never with user_id.
  • If Consumer fails, the whole request may fail with HTTP 500.
  • If Payment or Address fails, the endpoint must still return everything that was obtained successfully (including Consumer data).
  • When Address succeeds, the response must contain the first name and last name, not only the formatted address.

What to deliver

Describe and justify:

  1. The order of upstream calls and which ones can run concurrently.
  2. The shape of the response, including how a missing section is represented.
  3. How you handle HTTP status codes, malformed payloads, and timeouts.
  4. The tests that would prove the behavior is correct.

Also list the clarifying questions you would ask before building it, and state the assumptions you make when they are unanswered. If you write code, keep it short and focus on the orchestration logic.

Hints

Hint 1

Draw the dependency graph first: which call produces the input needed by the other two? That tells you what must be sequential and what can be parallel.

Hint 2

Think about how a client can tell the difference between 'balance is 0' and 'we could not find out the balance'. Your response contract should make that distinction explicit.

Hint 3

Give the request an overall deadline and derive each upstream timeout from the time remaining, rather than using fixed independent timeouts that could add up beyond the budget.

Hint 4

For tests, use fakes that record the arguments they receive. A test that fails if Payment is called with `user_id` will catch the most likely bug.