Building a Fault-Tolerant Aggregation Layer for Mobile App Startup
System DesignModel answerLast 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:
- Profile Service —
GET /profile?user_id=Xreturns{ account_id, name, preferences... } - Wallet Service —
GET /wallet?account_id=Yreturns{ cards, balance... } - Location Service —
GET /locations?account_id=Yreturns{ 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.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
Model Answer
Part 1: API Contract and Partial Failure Handling
Response Structure
Return HTTP 200 with a structured payload that explicitly indicates the status of each section:
{
"profile": {
"status": "success",
"data": { "account_id": "123", "name": "..." }
},
"wallet": {
"status": "failure",
"error": "timeout"
},
"locations": {
"status": "success",
"data": { "addresses": [...] }
},
"retrieved_at": "2026-01-15T10:30:00Z"
}
Status Code Logic
- Return 200 OK if we successfully retrieve at least the profile section (the minimum viable response).
- Return 503 Service Unavailable only if the profile service fails, since nothing else can proceed without
account_id. - Return 401/403 for authentication failures.
This contract lets clients distinguish between "no data available" (empty result) versus "couldn't fetch data" (error state), and render partial UIs when some sections succeed.
Part 2: Orchestration Strategy
Sequential then Parallel
- Call Profile Service first (required to get
account_id) - Once profile succeeds, call Wallet and Location services in parallel
Latency Budget Allocation
With a 600ms target:
- Profile Service: 250ms timeout
- Wallet + Location: 300ms timeout each (running concurrently)
- Overhead budget: 50ms for network, serialization
Concurrency Model
Use async I/O or thread pools to execute the parallel calls. Limit concurrent connections per downstream service (e.g., 50 connections max) to avoid overwhelming them during traffic spikes.
Part 3: Reliability Mechanisms
Timeouts
Set aggressive timeouts per service call (250-300ms). Distinguish between connection timeout (50ms) and read timeout (200-250ms) to fail fast on unresponsive services.
Retries
- Profile Service: 1 retry with exponential backoff (50ms initial), since it's critical
- Wallet/Location: 0 retries on timeout, 1 retry on 503/502, to avoid cascading delays
- Never retry on 4xx errors (except 429)
- Use jittered backoff to prevent thundering herd
Circuit Breakers
Implement per-service circuit breakers:
- Open after 50% error rate over 10 seconds
- Half-open state: allow 3 test requests after 30 seconds
- Prevents wasting time on persistently failing services
Fallback Strategies
When a service call fails:
- Check cache for stale data (see below)
- Return partial response with explicit failure status
- Never fabricate data or silently omit sections
Caching
Use a two-tier cache strategy:
- Profile data: Cache for 5 minutes (low volatility)
- Location data: Cache for 2 minutes
- Wallet data: Cache for 30 seconds or no cache (high correctness requirement)
Cache keys include user_id or account_id. On cache hit, still make async calls to refresh, but return cached data immediately if fresh enough. When service fails, serve stale cache up to 2x the normal TTL with a "stale: true" flag.
Part 4: Observability and Operations
Key Metrics
- Per-service latency: p50, p95, p99 for each downstream call
- Per-service availability: success rate, error rate by type (timeout, 5xx, circuit open)
- Partial response rate: percentage of requests returning incomplete data
- Cache hit rate and staleness served
- End-to-end latency of the aggregation endpoint
Alerting
- Alert when aggregate p99 exceeds 700ms
- Alert when profile service availability drops below 99%
- Alert when partial response rate exceeds 5%
- Alert when circuit breakers open
Runtime Tunables
Externalize these as configuration:
- Timeout values per service
- Retry counts and backoff parameters
- Circuit breaker thresholds and recovery times
- Cache TTLs per data type
- Feature flags to disable caching or specific services
Common Mistakes to Avoid
-
Treating all services equally: Profile is a hard dependency; others are optional. The orchestration must reflect this.
-
Using HTTP 500 for partial failures: This signals total failure to clients and monitoring tools. Use 200 with explicit section statuses instead.
-
Unbounded retries or timeouts: Without limits, one slow service can exhaust the thread pool and cascade failures to other requests.
-
Caching without TTL or staleness bounds: Stale payment data can cause transaction failures. Each data type needs its own freshness policy.
-
No distinction between error types: Timeouts should be handled differently than 404s or 401s. Transient errors warrant retries; deterministic errors don't.
-
Ignoring the dependency chain: Trying to call wallet/location before profile completes, or failing to short-circuit when profile fails.
-
Insufficient observability: Treating partial success as normal success in metrics makes it impossible to detect gradual degradation.
Trade-offs
- Complexity vs. resilience: Each mechanism (circuit breaker, cache, retry) adds code complexity but improves availability.
- Latency vs. freshness: Aggressive caching reduces latency but increases staleness risk.
- Fail-fast vs. attempt-all: Quick timeouts minimize latency but may discard requests that would eventually succeed.
- Consistency vs. availability: Returning partial data improves availability but complicates client logic and may show inconsistent state.
The right balance depends on product requirements, particularly how the mobile app behaves with partial data and whether users prefer fast-but-incomplete over slow-but-complete responses.