How to split the user interface along service lines and get fresh data to the browser.
key idea / coordinatorservice / good pathin progress / watch outproblem / failureneutral
Who owns the frontend?
Gateways exist to serve user interfaces, so start with the teams that build them.
From Building Microservices: a team that owns a slice end to end also stays close to its users. Specialists can be embedded, can split time across teams, or can form an enabling team that helps others become self-sufficient.
Frontend decomposition patterns
Microservices can have micro frontends too. The two usual ways are by page and by widget.
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
From Building Microservices: page-based splitting needs no clever JavaScript or iFrames: the user follows a link and a new page loads. Newman would choose it by default for a website, and widgets for a rich single-page app.
Decomposing the UI itself
The UI is often the last monolith. If every service team must edit one front-end codebase, autonomy is lost. From Practical Event-Driven Microservices Architecture, ch. 9.
Another aspect is the style of interaction. A CRUD screen edits fields and hides the business meaning. A task-based UI exposes what the user wants to do, which maps cleanly to commands and events.
Getting data to the UI
A screen often needs data from several services. The browser should not know about all of them. From Practical Event-Driven Microservices Architecture, ch. 9.
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.
Catalog read model
Search, filter and sort over many services.
Eventually consistent; lesson 11 shows how.
Pushing events to the browser
A UI that polls wastes calls and shows stale data. Events can travel on to the browser, but a browser cannot join a Kafka consumer group. From Practical Event-Driven Microservices Architecture, ch. 9.
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.
WebHooks
The server calls a URL you register.
Notifying another system, not a browser.
Describe the event contracts with AsyncAPI, the event-driven counterpart of OpenAPI. It documents channels and messages so teams can generate docs and code.
Recap
Dedicated frontend teams cause hand-offs. Prefer end-to-end teams, with micro frontends split by page or widget.
Serve the UI with an aggregating layer, backend for frontend or a read model. Push events to browsers through a client manager.
Quick check
Why can a browser not simply consume the Kafka topic?Show answer
It cannot take part in a consumer group. A client manager consumes the events and pushes them over WebSockets or server-sent events.