KatInterview

Launch-Time Data Gatherer with Partial Failure Tolerance

System DesignModel answer
MediumModel answerSystem Designasyncresiliencetimeouts

Last updated

Design an async service that merges four backend calls into one app-startup response, aborting on a critical failure and degrading gracefully on optional ones, within a fixed latency budget.

Context

A consumer mobile app makes one startup call, GET /v1/bootstrap?user_id={userId}, to load everything it needs for its first screen. If this call is slow or breaks, users feel it immediately. You are asked to design the service layer behind that endpoint.

The service gathers data from four internal backends:

  1. Profile service (critical): name, email, default delivery address.
  2. Active order service (optional): live status of any order in progress.
  3. Cart service (optional): items saved in the cart but not yet submitted.
  4. Experiment service (optional): feature flags and UI variants.

What to deliver

1. Contracts and interface

Define the response model and the aggregator class. Each of the four sections of the response must carry a status (SUCCESS, DEGRADED, or FAILED) plus either its payload or a fallback, and an optional error code. Use the following skeleton, or something equivalent:

class SectionStatus(Enum):
    SUCCESS = "SUCCESS"
    DEGRADED = "DEGRADED"
    FAILED = "FAILED"

@dataclass
class AggregatedSection:
    status: SectionStatus
    data: Optional[Dict[str, Any]] = None
    error_code: Optional[str] = None

@dataclass
class BootstrapResponse:
    user_id: str
    profile: AggregatedSection
    active_order: AggregatedSection
    cart: AggregatedSection
    experiment_flags: AggregatedSection

class BootstrapAggregator:
    def __init__(self, profile_client, order_client, cart_client,
                 experiment_client, timeout_ms: int = 300): ...

    async def get_bootstrap_data(self, user_id: str) -> BootstrapResponse: ...

2. Failure rules

  • If the profile call fails for any reason (timeout, 5xx, unauthenticated), the whole request fails with a suitable error such as 502 or 504.
  • If any optional call times out or errors, the section is marked DEGRADED (with a safe default) or FAILED, and the overall response is still HTTP 200.
  • All four calls run concurrently. Enforce both a per-call timeout and an overall deadline (default 300 ms).

3. Operational concerns

Explain or implement:

  • What happens when the client disconnects before the response is ready.
  • How the experiment section should fall back: a static local config, or an empty result.
  • What logging, metrics, and alerts would reveal downstream trouble before users report it.

Example

If the active order service times out while everything else succeeds, the response is HTTP 200 with profile, cart and experiment_flags marked SUCCESS, and active_order shaped like:

{ "status": "DEGRADED", "data": null, "error_code": "DOWNSTREAM_TIMEOUT" }

Walk through your design, including the code for the aggregator, its complexity, and the trade-offs you made.

Hints

Hint 1

Think of the request as one must-have call plus three nice-to-have calls sharing a single time budget. Start all four at once so total latency is about the slowest call, not the sum.

Hint 2

Do not just gather everything and look at the results afterwards. Watch for the profile task finishing (or failing) as tasks complete, so a critical failure can cancel the rest immediately instead of waiting for the full deadline.

Hint 3

For each optional section, pick the fallback that cannot mislead the user. An empty cart says the items vanished, while an all-features-off flag set is a safe default. Also make sure a cleanup block cancels unfinished tasks on every exit path, including client disconnect.