Skip to content
System Design Lab
Microservice Patterns

UI Composition

Build pages from fragments owned by different teams — assembled on the server or in the browser — and give optional fragments their own deadlines, so one slow team cannot make the whole page slow.

Intermediate 4 min read· Updated 2026-11-18

What you will learn

  • Compare server-side page-fragment composition with client-side composition (micro-frontends).
  • See how one slow fragment delays an all-or-nothing page.
  • Apply per-fragment timeouts, fallbacks and streaming.
  • Keep a consistent look and shared dependencies under control.

Before you start

Overview

A newspaper's front page has sections from different desks. If the sports desk is late, the paper still goes to print — with a placeholder or yesterday's results — rather than holding the whole edition.

When backend teams own business capabilities end to end, the UI can follow: each team owns fragments (product details, recommendations, reviews) that are composed into one page. Server-side composition assembles HTML fragments in a page service or at the edge (SSI, ESI, a composition layer); client-side composition loads team-owned components into a shell in the browser (micro-frontends, module federation, web components).

Run it

A product page is composed from four fragments; recommendations becomes slow at t = 10 s. Compare page latency when the composer waits for everything (A) and when recommendations has a 150 ms deadline and a fallback (B).

Loading simulation…

Server-side vs client-side

Server-side fragmentsClient-side (micro-frontends)
First paint / SEOComplete HTML, good SEONeeds SSR or a fast shell
Slow fragmentMust be handled with deadlines or streamingOnly its area of the page waits
Team independenceFragment services deploy independentlyBundles deploy independently
RisksComposer becomes a bottleneckDuplicate dependencies, inconsistent UX, larger downloads

Deadlines per fragment

Compose in parallel; optional fragments get a deadline and a placeholder
public Page render(long productId) {
    var header  = fragments.fetch("header", productId);                         // required
    var product = fragments.fetch("product", productId);                        // required
    var recs    = fragments.fetch("recommendations", productId)
                           .completeOnTimeout(Fragment.placeholder("recommendations"), 150, MILLISECONDS)
                           .exceptionally(e -> Fragment.placeholder("recommendations"));
    var reviews = fragments.fetch("reviews", productId)
                           .completeOnTimeout(Fragment.placeholder("reviews"), 200, MILLISECONDS);
    return Page.of(header.join(), product.join(), recs.join(), reviews.join());  // all run concurrently
}

Trade-offs

BenefitsCosts
OwnershipTeams ship UI for their capability without a central frontend bottleneck.Shared design system, routing and state need clear governance.
ResilienceOptional fragments can fail without breaking the page.Only if every fragment has a deadline and a fallback.
PerformanceFragments can be cached and rendered independently.Many fragments mean many calls; client-side composition can bloat bundles.

Production considerations

  • Classify fragments as essential or optional, and give optional ones placeholders.
  • Share a design system and a small set of runtime dependencies across micro-frontends.
  • Cache fragment output at the edge where it is not personalised (CDN).
  • Monitor each fragment's latency and error rate separately.

Further reading

Related topics