KatInterview

Building a Fault-Tolerant Aggregation Layer for Mobile App Startup

System DesignModel answer
MediumModel answerSystem Designmicroservicesfault-toleranceapi-design

Last updated

Design an API that combines data from multiple backend services into one response, handling failures gracefully when services are down or slow.

Problem Context

You're building an aggregation layer for a mobile application. When users open the app, a single network call must return all the information needed to display the home screen. This data comes from three different backend services that you don't control, and you need to combine their responses into one unified payload.

The Backend Services

Three separate services provide the necessary data:

  1. Profile Service — GET /profile?user_id=X returns { account_id, name, preferences... }
  2. Wallet Service — GET /wallet?account_id=Y returns { cards, balance... }
  3. Location Service — GET /locations?account_id=Y returns { saved_addresses... }

Notice that services 2 and 3 require an account_id that only service 1 can provide from the original user_id.

Your Task

Create an aggregation API:

  • Endpoint: GET /app-init?user_id=X
  • Purpose: Accept a user_id, call the three backend services, and return one combined response containing profile data, wallet data, and location data.

The Challenge

Your API must remain functional even when backend services misbehave. Services may timeout, return errors, respond slowly, or become temporarily unavailable. Rather than failing completely, your API should return whatever data it can successfully retrieve.


Design Considerations

Work with these assumptions (validate them during discussion):

  • This call happens during app launch and directly impacts perceived performance — target around p99 ≤ 500-700ms total latency.
  • The operation is read-only with no side effects.
  • Standard distributed system constraints apply: finite connection pools, no transactions across services, potential network partitions.
  • Be explicit about timeout values, retry attempts, and cache durations rather than leaving them unspecified.

What to Address

Part 1 — Response Structure and Failure Semantics

Define what the response looks like and how clients should interpret it when only some backend calls succeed. Specify both HTTP status codes and response body structure so clients can handle partial data reliably.

Part 2 — Call Sequencing and Parallelization

Explain how you'll order the three service calls given their dependencies, which calls can run simultaneously, and how you'll keep total latency under control.

Part 3 — Resilience Mechanisms

Describe your approach to timeouts, retry logic, circuit breakers, fallback strategies, and caching. Explain how these techniques work together to improve reliability.

Part 4 — Monitoring and Runtime Control

Outline what metrics you'll track, what alerts you'll configure, and which parameters should be adjustable without code changes.


Questions to Clarify

Before designing, consider asking:

  • How critical is each data section? Can the app function if wallet or location data is missing, or are all three mandatory for rendering?
  • Where does user_id come from? Is it from an authenticated session, or do we need to validate it?
  • What's the acceptable response time? What latency budget should each backend call have?
  • Are partial responses useful? Should we return 200 with partial data, or fail the entire request if any call fails?
  • How fresh must each data type be? Can we cache profile data longer than payment information?
  • What's the expected traffic volume? Are there rate limits per user or per service?
  • Are there correctness requirements? For example, should we never show outdated payment methods?

Hints

Hint 1

Think about which service call must complete before others can begin, and which can run in parallel to minimize total latency.

Hint 2

Consider returning a 200 status with flags indicating which sections succeeded, rather than failing the entire request when one service is down.

Hint 3

Different data types have different staleness tolerances: user profiles change rarely, but payment methods may need stricter freshness guarantees.