UI patterns: micro frontends and live updates
FTGO's backend is split into services, but its web app is still one big codebase owned by one team, and it only learns about changes when it asks. This chapter shows how to split the user interface along service lines and how to push fresh data to the browser.
key idea / coordinator service / good path in progress / watch out problem / failure neutral
In chapter 12 we gave FTGO's web and mobile clients one entry point: an API gateway, one backend per frontend (BFF), and GraphQL for flexible queries. That left one problem open: behind the gateway, the user interface itself is still one big frontend, owned by one team, and it shows data that is stale the moment it loads.
How do FTGO's service teams ship their own parts of the screen, and how does a customer see "your order is on its way" without pressing refresh? By the end you can choose between page-based and widget-based micro frontends, design task-based screens, feed each part of a page its data, and push events to browsers.
One frontend team becomes the bottleneck
Gateways exist to serve user interfaces, so start with the people who build those interfaces.
The Kitchen team wants to show customers an estimate of when their meal will be ready. Kitchen Service already computes it. But the FTGO web app belongs to a separate frontend team, the gateway to a platform team, and the estimate needs a new database column owned by a data team. One small control needs three tickets in three backlogs, and it ships a month later.
Splitting the backend into services gave each team its own code and its own releases. A layered organization, with one team per technical layer, takes that autonomy straight back: every feature crosses every layer, so every feature needs a hand-off.
Give each team a whole slice of the product: its screens, its services and its data. The Kitchen team builds the estimate on the page as well as in Kitchen Service, and ships it without waiting for anyone.
Organizations keep dedicated frontend teams for a few reasons. Each reason has another answer that avoids the hand-offs.
Scarce specialists can be embedded in a team, split their time across a few teams, or form an enabling team that helps others become self-sufficient. Some companies accept less consistency on purpose: the AWS console varies from service to service because Amazon values team autonomy more. A team that owns its slice end to end also stays close to the customers and restaurants who use it.
Teams now need frontend skills, and FTGO needs a style guide and shared components to stay coherent. And the ownership is only on paper while the code is one front-end codebase: the Kitchen team still has to edit, test and release the whole web app to change one panel.
Split the frontend: pages, widgets and a shell
Ownership needs code boundaries to match. The UI is often the last monolith left after the backend is split.
FTGO's web app is one single-page application. The order page shows the menu (Restaurant team), the basket (Ordering team) and the delivery estimate (Delivery team). A change to the delivery estimate means rebuilding and redeploying the whole app, and a broken build from the Restaurant team blocks the Delivery team's release.
Split the frontend into parts that different teams build and deploy independently, just as services split the backend. Split either by page or by widget.
Page-based splitting is the simple one. Each team serves whole pages, and the URL decides who answers: /restaurants/ goes to the Restaurant team's frontend, /orders/ to the Ordering team's. It needs no clever JavaScript and no iFrames. The user follows a link and a new page loads. Choose it by default for a website.
Widget-based splitting suits a rich single-page app where one screen mixes several teams' work. A shell, or container page, owns navigation and layout. Each team ships a fragment that the shell places on the page, and each fragment talks to its own service or read model.
Widgets must not call each other directly, or they would couple just like services that share code. They talk the way services do: one widget raises a custom browser event, and the others subscribe and react.
| Pattern | Pick it when | Watch out |
|---|---|---|
| Monolithic frontend | One team owns UI and services | Silos if many teams share it |
| Page-based | You are building a website | Cross-cutting features fit badly |
| Widget-based | A rich SPA with several teams | Bundle size, clashing dependencies |
| API calls only | A feature does not fit a page or widget | Each client re-implements it |
Self-contained systems take the page-based idea furthest: each team owns a complete web app with its own UI, logic and data, and the apps link to each other instead of sharing any UI code.
Widgets can bloat the page, because each may bring its own copy of a framework, and their dependencies can clash. Features that cut across pages, such as a basket badge in every header, fit neither split well. And splitting the code does not fix screens that were designed around database tables instead of what users do.
Screens that say what the user means
Once a team owns its screens, it can also change how those screens talk to its service.
FTGO's "edit order" screen is a form with every field of the order and one Save button. Order Service receives UpdateOrder with the whole order. Did the customer change the delivery address, or cancel? Order Service has to diff the fields to guess, and the events it publishes say only "order updated", so Kitchen Service and Delivery Service have to guess too.
Design screens around the tasks users want to do, such as "change address" or "cancel order". Each task sends one small command, and the service publishes an event that says exactly what happened.
A CRUD screen (create, read, update, delete) edits fields and hides the business meaning. A task-based screen exposes intent, and that intent maps cleanly to the commands and domain events from chapter 3, to an event-sourced history (chapter 10) and to CQRS views (chapter 11).
There are more commands and screens to design, and the team must understand the user's tasks, not just the table. The commands handle writes well. Reads are still awkward: the order page needs data from several services at once.
Feed each part of the screen its data
Commands go to one service. A screen usually reads from several.
The "My orders" page shows each order's status (Order Service), the restaurant name (Restaurant Service) and the courier's position (Delivery Service). If the browser calls all three for every order, it must know every service's address and API, a slow mobile connection makes dozens of round trips, and the page breaks whenever one service changes.
The browser should not know about all those services. Hand it one answer instead: joined at request time, or prepared ahead of time from events.
Give each page or widget a single source: an aggregating layer or BFF that composes service calls (chapter 12), or a read model that events keep up to date (chapter 11). The team that owns the widget usually owns its source too.
| Option | Good for | Watch out |
|---|---|---|
| Aggregating layer | One entry point that hides many services. | Can become a central coupling point. |
| Backend for frontend | One tailored API per client (web, mobile). | More code to own and keep in sync. |
| API composition | Joining a few small responses. | Slow and fragile for large joins, filtering or paging. |
| Read model | Search, filter and sort over many services, such as a restaurant catalog. | Eventually consistent; chapter 11 shows how. |
Composition at request time stops scaling as a screen grows. The page waits for the slowest service, and one service that is down fails the whole page.
An aggregating layer can become a central point that every team must change. A read model is eventually consistent and is one more store to run. And either way the page is a snapshot: once "My orders" has loaded, it does not know that the courier just picked up the meal.
Stop polling: push events to the browser
The services already publish events when an order changes. The browser just never hears them.
To show live order status, the FTGO web app polls Order Service every 5 seconds. Say 10,000 customers have the page open at dinner time: that is 2,000 requests a second, and almost every answer is "nothing changed". When the courier does pick up the meal, the customer still sees the old status for up to 5 seconds.
Polling wastes calls and still shows stale data. The obvious fix is to let the browser listen to the order events, but a browser cannot join a Kafka consumer group: it is not a trusted server, it comes and goes, and it must see only its own customer's orders.
Put a small service between the broker and the browsers. It consumes the events, keeps track of which browsers are connected and for which customer, filters the events per user, and pushes each one down an open connection.
The connection to the browser can use one of a few techniques:
| Technique | How it works | Use when |
|---|---|---|
| WebSockets | Two-way, long-lived connection. | The UI also sends frequent messages. |
| Server-sent events | One-way stream from server to browser over HTTP. | The UI only needs updates, like FTGO's order status. |
| WebHooks | The server calls a URL you register. | Notifying another system, such as a restaurant's own software, not a browser. |
Now the event contract reaches all the way to the screen, so describe it as carefully as a REST API. AsyncAPI is the event-driven counterpart of OpenAPI: it documents channels and messages, so teams can generate documentation and code from one description.
The client manager holds thousands of long-lived connections, must authenticate each one, and must cope with browsers that disconnect and miss events. One page now depends on micro frontends from several teams, their data sources, the broker and the push channel. Each part can work alone and the page can still break where they meet.
Patterns in this chapter
| Pattern | Problem it solves | What it costs |
|---|---|---|
| Stream-aligned teams own their UI | Every feature needs hand-offs between UI, service and data teams | Teams need frontend skills; consistency needs a style guide and shared components |
| Page-based micro frontends | One frontend codebase couples every team's releases | Cross-cutting features fit badly |
| Widget-based micro frontends | One rich screen mixes several teams' work | Page weight, clashing dependencies, a shell to maintain |
| Self-contained systems | Teams still share UI code | Less consistency across apps |
| Task-based UI | CRUD forms hide what the user meant, so events say only "updated" | More commands and screens to design |
| Aggregating layer or BFF per screen | The browser would call many services per page | A coupling point; slow and fragile for big joins |
| Read model for the UI | Search and lists that join data from many services | Eventually consistent; another store to run |
| Client manager with server push | Polling wastes calls and still shows stale data | Long-lived connections, per-user filtering, missed events on reconnect |
Recap
- Separate frontend, service and data teams turn every feature into hand-offs, so give stream-aligned teams their whole slice, UI included, and keep the look consistent with a style guide and shared components.
- Micro frontends let those teams deploy their UI independently: split by page for a website, by widget inside a shell for a rich single-page app, and let widgets talk through browser events.
- Task-based screens send small commands such as "change address", so services can publish events that say exactly what happened.
- Each page or widget should make one call, to an aggregating layer or BFF for small joins or to a read model for search, filtering and big lists.
- A browser cannot join a consumer group, so a client manager consumes events, filters them per user and pushes them over WebSockets or server-sent events.
Quick check
Show answer
It cannot take part in a consumer group, it is not trusted with every customer's events, and it connects and disconnects at will. A client manager consumes the events, filters them per user and pushes them over WebSockets or server-sent events.
Show answer
The frontend is still a monolith, so every team's release is tied to every other team's build. Widget-based micro frontends fix it: a shell composes independently deployed fragments, so the Delivery team ships its panel on its own. The panel gets its data from one source owned by the Delivery team, and talks to other widgets only through browser events.
Show answer
They lose the intent: Order Service can only publish "order updated", so Kitchen and Delivery must diff fields to learn whether the address changed or the order was cancelled. A task-based UI sends specific commands such as ChangeAddress, which produce specific events such as AddressChanged.
FTGO now has many services, many independently deployed frontends, gateways, read models and a push channel. Each team can change its part on its own schedule, so how does anyone know the whole thing still works after a change?