UI Interaction with an Event-Sourced Backend
Source references:
Event Sourcing- UI Interaction Design Pattern.md;
Architecture- Event Sourcing.md.
Problem
Event-sourced backends are eventually consistent: a user action becomes
a command → event → projection update over multiple hops. Naive UIs that
poll or wait synchronously either feel unresponsive or hide the true state.
At V3 scale (~6 000 concurrent UI users at peak, ~7K backend calls/minute
— see ../context/capacity-model.md),
polling every entity every few seconds is not viable, and refreshing after
every write silently masks command failures.
We need one interaction model that:
- Gives users immediate feedback for every action (optimistic).
- Delivers scoped real-time updates — no bombarding UIs with events they don’t care about.
- Reveals command failures to the initiating user without leaking them to other viewers.
- Preserves CQRS: reads and writes take separate paths.
Solution
CQRS at the edge + SignalR-driven scoped notifications, backed by a BFF Sidecar cache for hot entities.
┌────────┐ writes (POST → 202) ┌──────────┐ command ┌─────────────┐
│ UI │───────────────────────▶│ BFF │────topic───▶│ Event Store │
│ (SPA/ │◀─── reads (list) ─────│ (APIM) │ │ (aggregate)│
│ MFE) │ └────┬─────┘ └──────┬──────┘
│ │◀─── reads (hot entity)──────┤ │ events
│ │ ▼ ▼
│ │ ┌───────────┐ hot-entity ┌───────────┐
│ │◀── SignalR (scoped ───│ Sidecar │◀─────────────│ Integration│
│ │ notifications) │ + cache │ │ topic │
└────────┘ └───────────┘ └───────────┘
│ SignalR fan-out
▼
┌──────────────┐
│ SignalR Hub │
│ (Premium AZ) │
└──────────────┘
Core rules:
- Reads take two paths. List/dashboard reads always hit the Event Store operational (projection) API via the BFF — filters can be arbitrary; we do not cache large sets. Entity-detail reads hit the BFF Sidecar, which lazy-loads the entity into a Redis-backed hot cache with LRU + TTL eviction.
- Writes are always async. BFF validates the command shape, publishes
to the Event Store command topic, and returns
202 Acceptedwith a correlation ID. The UI does not wait for the projection. - Optimistic UI updates. On submit the UI transitions the local state immediately (spinner or provisional value) so users perceive the app as responsive.
- Scoped SignalR groups. On login the UI opens one SignalR connection
per user. It joins groups on demand:
{Portal}-Dashboard-Group— dashboard/list-relevant events only (created, assigned, unassigned, closed).{Entity}-{EntityId}-Group— full event stream for that entity while the details page is open (also joined on submit to catch the ack).{Customer}-{Tenant}-Group— cross-cutting customer notifications.
- Sidecar owns fan-out selection. The Sidecar consumes every event,
updates its cache, and decides:
- Publish to dashboard group only if the event impacts a list view.
- Publish to entity group if the entity is currently hot.
- Send command success/failure directly to the initiating user
(
Clients.User(userId)), never to a shared group — failure signals are private.
- Failure semantics are explicit. On a
CommandFailed/CommandDeniedevent the UI reverts the optimistic state and surfaces a retry affordance to the originating user only.
When to use
- Use for any UI backed by an event-sourced service (Veritas portal, Alya workbench, adaptive-card responders via Pigeon).
- Use whenever multiple concurrent viewers may share an entity (SOC advisor + customer looking at the same incident).
- Do not use raw polling loops for entity state — polling is acceptable only for long-tail catch-up after a SignalR reconnect or for cold reports.
- Do not use synchronous request/response for writes — the write model is asynchronous by design.
Consequences
Positive
- Users perceive the app as instantaneous despite eventual consistency.
- Real-time updates are targeted — no per-user firehose.
- Command failures are visible to the actor without leaking to others.
- Sidecar cache absorbs read load for hot entities and shields the Event Store projection API from repeated point reads.
- Aligns cleanly with Async REST, ECST, and the CQRS split enforced across V3.
Negative
- Multiple moving parts (Hub, Sidecar, Redis, projection API) — more code and more failure surface than a synchronous CRUD stack.
- Optimistic UI needs careful rollback UX for every editable field.
- Group-membership bookkeeping (join on nav-in, leave on nav-out / disconnect) is easy to get wrong and leaks connections.
Failure modes
- SignalR disconnect — UI must reconcile via a REST refresh on reconnect; assume it missed events during the outage.
- Sidecar cache miss under load — first request warms the cache; guard the Event Store projection API with request coalescing.
- Command accepted (
202) but never acknowledged — surface a correlation-ID-based “still processing” state after N seconds; do not silently succeed. - Group membership leak — hub must evict groups on connection close;
UI must
LeaveGroupon route change to avoid noisy cross-page updates.
References
- ADRs: ADR-0007 Async REST; ADR-0006 CQRS / event sourcing; Redis cache pattern (no dedicated ADR).
- Patterns: Async REST; ECST; Idempotent write; Auth / AuthZ.
- WA:
well-architected/performance-efficiency/ui-responsiveness/;well-architected/reliability/graceful-degradation/.
Applied in
- Veritas — customer & advisor portals; primary consumer of this pattern for incident, ticket, service-request lists and details.
- Alya — Defender Workbench; same pattern with internal-persona scope.
- Pigeon — adaptive-card acks in Teams follow the same 202 + async-ack contract (SignalR replaced by Teams bot callback).
- Watchtower BFF — publishes the events the Sidecar fans out.