---
title: Data Flow & Gateway Integration
summary: Typed transport contracts, retry and idempotency rules, optimistic concurrency with ETags, and real-time streaming channels.
owners:
  - catalog-experience-team
badges:
  - content: Architecture
    backgroundColor: purple
    textColor: purple
  - content: Reference
    backgroundColor: blue
    textColor: blue
---

## Purpose & Scope

This reference governs how **Storefront**, **Commerce**, and **Backoffice** communicate with backend capability services (**Catalog API**, **Basket API**, **Ordering API**, **Rating API**, and **Chat API**) through the **API Gateway**. It defines transport standardization, resilience policies, optimistic concurrency controls, and real-time streaming patterns.

## Layered Data Flow

The visual below traces how feature slices interact with server query caches, minimal client state, resilient HTTP transport, and real-time streaming channels across the gateway boundary.

<MermaidFileLoader file="mermaids/007-architecture-and-state-design-diagram-2.mmd" />

## Architectural Principles & Rules

- **Gateway-only communication:** Frontend surfaces never call internal backend services directly; every request routes through the **API Gateway** using shared, typed domain contracts.
- **Safe retry & idempotency discipline:** Transient timeouts, rate-limit responses (honoring server retry-after hints), and safe read methods retry automatically with bounded backoff. Non-idempotent writes only retry when carrying an explicit request idempotency identifier.
- **Optimistic concurrency for staff edits:** Mutable administrative resources in **Backoffice** (such as catalog items and order summaries) exchange entity tags (`ETag`) on reads and require matching preconditions on updates to prevent silent lost updates.
- **Zero-retry on authorization & conflict failures:** Missing credentials or stale precondition conflicts never retry automatically; the UI surfaces explicit re-authentication or reload-and-merge prompts.

<Admonition type="warning" title="No Ad-Hoc Network Calls in UI Components">
	Feature components must consume centralized query and mutation abstractions rather than issuing
	raw network requests. This guarantees uniform authorization token injection, correlation headers,
	retry rules, and cache key consistency.
</Admonition>

## Patterns & Boundaries

| Concern / Surface               | Architectural Approach                                                                            | Responsibility Boundary                                                                                       | Key Trade-off                                                                                                       |
| :------------------------------ | :------------------------------------------------------------------------------------------------ | :------------------------------------------------------------------------------------------------------------ | :------------------------------------------------------------------------------------------------------------------ |
| **Standard REST & Query Reads** | Centralized typed HTTP client with normalized cache keys and bounded retries                      | Shared transport layer handles headers, retries, and error classification; feature slices handle presentation | Slight abstraction overhead compared to inline fetches, repaid in consistent error and retry behavior               |
| **Optimistic Concurrency**      | Conditional reads and precondition-guarded writes via `ETag` headers                              | **Backoffice** surfaces detect precondition conflicts and prompt staff to refresh before overwriting          | Requires staff to resolve concurrent edits manually rather than silent last-write-wins                              |
| **Dashboard Metrics Stream**    | Initial snapshot load followed by authenticated Server-Sent Events (SSE) with exponential backoff | **Backoffice** dashboard subscribes to live ordering metrics; **Ordering API** pushes incremental updates     | Maintains persistent connection per active admin session; falls back cleanly via bounded reconnects                 |
| **Conversational AI Stream**    | Server-side assistant runtime forwarding customer identity to **Chat API** over AG-UI             | **Storefront** mediates streaming responses and declarative UI cards; **Chat API** owns agent orchestration   | Adds a lightweight server-side proxy hop in **Storefront** to keep agent integration decoupled from browser clients |

<Accordion title="HTTP Status Recovery Matrix">

- **Not Modified:** Conditional reads retain the existing cached entity without re-downloading payloads.
- **Unauthorized:** Immediate halt of retries; customer surfaces redirect to sign-in while preserving the return destination.
- **Timeout / Rate Limited:** Automatic bounded retry respecting server-provided backoff windows.
- **Precondition Failed:** Explicit conflict notification in **Backoffice** prompting the operator to reload the latest state.
- **Server Errors:** Retried only for idempotent operations or writes carrying a correlation idempotency key.

</Accordion>

## Quality & Operational Impact

- **Reliability:** Bounded retries with idempotency safeguards absorb transient network blips without creating duplicate orders or basket mutations.
- **Data Integrity:** `ETag` precondition checks protect **Backoffice** operators from accidentally overwriting concurrent catalog or order updates.
- **Responsiveness:** Real-time SSE and AG-UI streaming deliver live operational metrics and conversational AI responses without polling overhead.
