Deployment Model
This page describes what you run when you run Wow: the services and their nodes, how nodes find each other and share work, which infrastructure each service needs, and the assumptions the design makes about the network. Read it before you plan a deployment.
Services and nodes
A service is one deployable application. It hosts one or more bounded contexts: their aggregates, their processors and their HTTP API. A node is one running instance of a service. A service runs as many nodes as it needs, and every node of a service runs the same code.
The nodes of a service share the work through partitions. Each context's log has a fixed number of partitions, 64 by default, and each partition has one owner at a time. Ownership is a lease kept in the service's own store: there is no ZooKeeper, no Kafka consumer group and no registry. Every node computes the same assignment from the list of live members and takes or releases leases to match it. When a node joins or leaves, about one partition in N moves.
A node keeps one membership record per service, listing the contexts and topics it takes part in, and reads the service's members once for all of them; only the leases are per context. The store work of this coordination therefore grows with the number of nodes and, for the leases, with the contexts each runs: with the defaults, about 1.3 operations a second per node plus 1.3 per context a node runs (15 contexts on 10 nodes: about 210 a second), whatever the command traffic.
The owner of a partition executes the commands for its aggregates and runs every subscription over it. A command that arrives at another node is forwarded to the owner. When no owner can be reached, for example while a partition changes hands, the receiving node runs the command itself, and the aggregate's version keeps the result correct. Writing: admission to append explains the rules.
A node stuck in its reconcile
A node reconciles its partitions every second: it hands off those that are no longer its share and takes those that are. When one reconcile finishes no step, no partition taken or handed off, for wow.cluster.reconcile-timeout (1 minute), the node is stuck, usually on a subscription that does not stop or a partition that does not start. It then fences the context's partitions:
- It leaves the members, so the other nodes take its share.
- Its partitions stop taking commands at once. A command it is still given is forwarded to the partition's next owner.
- Each partition's commands already running finish, or
wow.cluster.drain-timeout(10 seconds) passes; only then does the node stop renewing that partition's lease. It sends no release: the lease expires withinwow.cluster.lease-ttl(10 seconds), and another node takes the partition on its next reconcile. With the defaults the partitions are another node's about 21 seconds after the fence, and at no moment do two nodes both hold one. - It stops the partitions' timers.
The fenced node still reads its command topics, and forwards the commands it reads. Its subscriptions keep running over the partitions it gave up, since stopping them is usually what it is stuck on. Their effects, a projection's write or a notification, can therefore repeat beside the new owner's until the reconcile moves again or the liveness check restarts the node (wow.health.liveness.stall-timeout, 3 minutes). That is the same exposure as a lease lost while a reconcile is busy. Once the reconcile moves again, the node is a member again, stops the partitions it gave up and takes its share back.
A fence is logged at WARN, with the context and how long no step finished, and counted by wow.cluster.fence.notices (wow.kind=fenced), as is its recovery (recovered), so an operator sees it before the liveness check does. A reconcile that is long but keeps finishing steps, one taking many partitions from a slow store say, is not stuck. wow.cluster.reconcile-timeout must be longer than wow.cluster.lease-ttl and wow.cluster.drain-timeout, or the node does not start.
A node is watched from its first reconcile on, while it starts. A start whose first reconcile finishes no step is fenced the same way, so the other nodes take the share it claimed. The start itself waits: the call it is stuck on cannot be cancelled. Readiness stays DOWN, as for any node that is not running, and its ownership details mark the group fenced. Once the reconcile has finished no step for wow.health.liveness.stall-timeout (3 minutes), the node's liveness is DOWN too, with stalled: reconcile and the group, so the orchestrator restarts it. A store call that fails is not a hang: the start fails with the store's error.
While the lease store fails
A lease store that cannot answer, a MongoDB replica set without a majority or a PostgreSQL primary that does not reply, makes every lease write wait until it times out. The renewals of a node's leases stop succeeding, and a lease left unrenewed for wow.cluster.lease-ttl less wow.cluster.renew-interval (7 seconds) stops its partition before it may expire elsewhere. Asking for every one of those partitions again on each reconcile would keep that many writes waiting on the store, for every context and node, and keep a degraded store at its limits. So once the store fails, the node holds back its acquisitions on that store:
- The first sign opens the hold: an acquisition, a renewal or a heartbeat that failed, or leases left unrenewed past that margin. Every context and topic of the node on the same store shares it: the first failure any of them meets holds all of them.
- While held, the node asks no acquisition for a window that starts at
wow.cluster.reconcile-intervaland doubles with each failure up towow.cluster.lease-ttl, drawn at random below that bound so the nodes do not ask in step. Then it asks one at a time. - The answer to that one acquisition, the probe, ends the hold, whether it got the lease or another node holds it, and the next reconcile takes every missing partition. A heartbeat or a renewal the store answers meanwhile ends only the current window, so the probe goes at the next reconcile: a store slow enough to time out acquisitions while it still answers heartbeats is asked one acquisition at a time, never every missing partition after each heartbeat.
- A single renewal or heartbeat that failed while the node missed no partition is ended by the next call the store answers, since no probe would come.
Each lease call also takes at most the TTL it is given: an acquisition or a renewal the lease's (wow.cluster.lease-ttl, 10 seconds), a heartbeat the member's (wow.cluster.member-ttl), and none longer than the store's own timeout (wow.mongo.operation-timeout, wow.postgres.operation-timeout). A lease's expiry is computed when its call starts, so one that came back later would be expired already; and on PostgreSQL, whose lease store runs its calls one at a time, a renewal never waits behind an acquisition held longer than that. A call given up on the node's side is not undone on the store, which may still apply its write: a lease may then show in the store (wow_lease) that no node believes it holds. Nothing needs to be done about it: no node renews it, so it expires on its own within the TTL, and the next reconcile acquires it.
A node that crashes leaves its member record (wow_lease_member) behind, and a node restarted writes a new one, its id changing with each start. A heartbeat deletes the records of its service expired for more than ten member TTLs (100 seconds at the default wow.cluster.member-ttl), at most once per member TTL, after it wrote the node's own record; a delete that fails or does not answer within a quarter of the TTL is given up, and the heartbeat goes on. Reads pass over an expired record either way, so a record waiting to be deleted changes nothing.
Renewals and heartbeats are never held: one call per round each, they keep what the node still holds and tell it when the store answers. A node that takes over a dead node's partitions is never held either: its acquisitions find the leases still held until they expire, and the store answers them. Once a store recovers, the partitions come back within about one window and one reconcile: up to wow.cluster.lease-ttl more than without the hold. The node logs the hold once when it starts and once when it ends (Troubleshooting).
Two ports
Each node listens on two ports:
| Port | Serves | Who reaches it |
|---|---|---|
Public (server.port) | The HTTP API: commands, queries, state reads, the Manifest, OpenAPI; Actuator's health endpoint | What networkPolicy.public.from admits, the gateway by default: clients and ingresses go through it, or are added there |
Internal (wow.internal.port, 9090 by default; the chart sets it on the pod from ports.internal, 9093 by default) | The cluster channel between the service's own nodes; wait signals from any service; synchronous calls and reads from other services | Nodes of the system only |
The internal port is HTTP/2 without TLS (h2c). It must never be reachable from outside the platform: no public load balancer, ingress or port mapping points at it, and a network policy lets only the platform's own pods reach it. It takes no token: every request to it names the service it comes from in the Wow-Service header, and the network is its boundary (Secure a deployment).
Each node advertises the address other nodes reach its internal port at:
wow.node.idnames the node among the service's members; a new one is generated at each start unless set.wow.internal.hostis the interface the internal port binds. Bind it to the node's private address. Unset, a node in a development profile binds127.0.0.1, and any other the address this host's name resolves to; a node refuses to start when that address is a public one, since the port takes no credential. An address you name is taken as written.wow.node.addressis thehost:portother nodes use. By default it is the bound address with the internal port (this host's address when the port binds every interface); set it only when the peers reach the node at another address, as behind NAT, on a host with several interfaces, or in a StatefulSet whose pods have stable DNS names. It names its port, 1 to 65535, and an IPv6 host in brackets ([fd00::7]:9090); an address without a port, with port 0 or past 65535, or a bare IPv6 literal refuses the start.
On Kubernetes, the eShop's ordering manifests take the node id and the bound address from the pod, and advertise that address, the pod's IP:
env:
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
# The ports the Services and the probes name: the chart's, whatever the image's configuration says.
- name: SERVER_PORT
value: {{ .Values.ports.http | quote }}
- name: WOW_INTERNAL_PORT
value: {{ .Values.ports.internal | quote }}
# The node id is the pod's name: a replaced pod is a new member.
- name: WOW_NODE_ID
value: $(POD_NAME)
# The internal port binds the pod's private address only, and the node advertises that address: a
# Deployment's pods have no DNS name of their own.
- name: WOW_INTERNAL_HOST
value: $(POD_IP)
# The namespace a peer's SRV name is in, unless wow.peer.dns.namespaces places the peer elsewhere.
- name: WOW_PEER_DNS_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
{{- with .Values.env }}
{{- toYaml . | nindent 12 }}
{{- end }}A Deployment's pods have no DNS name of their own (a headless service publishes <pod>.<service> only for pods with spec.hostname), so the node advertises its IP. The headless service is named after the service, eshop-ordering-service-cluster: its SRV records name every node's address, the nodes that are not ready included, and the other services find its nodes there by the service's name alone. Wow's chart (Kubernetes) renders all of it, and the eShop ordering's values are a complete template for one service.
What a service needs
| Component | When | What for |
|---|---|---|
| PostgreSQL or MongoDB | Always, in production | The log, snapshots, checkpoints, leases, the failure ledger, reserved keys and timers. MongoDB must be a replica set. |
| Kafka | When events or commands cross contexts, or an aggregate type's commands are routed through Kafka | Published streams, command topics, receipts. See Kafka. |
| ClickHouse | When the service writes the warehouse or serves datasets | The ClickHouse sink and dataset queries. |
| Elasticsearch | Optional | Copies of snapshots and event streams for full-text search. It never holds the log. |
Choose a backend
A node keeps its log, snapshots, checkpoints, leases, failure ledger, reserved keys and timers in one backend, chosen by wow.backend:
| Backend | Module | The application provides |
|---|---|---|
postgres | wow-postgres | a javax.sql.DataSource: the host's of spring.datasource.url (with HikariCP), or the application's bean |
mongo | wow-mongo | a com.mongodb.client.MongoClient on a replica set: the host's of spring.mongodb.uri, or the application's bean; the database is wow.mongo.database |
memory | none | nothing: one node, whose data does not outlive it |
auto, the default, takes PostgreSQL or MongoDB by the bean the application has. Without either, a node refuses to start, unless a development profile is active; then it runs in memory and says so. The eShop's ordering service moves to PostgreSQL with its postgres profile:
spring:
config:
activate:
on-profile: postgres
datasource:
url: jdbc:postgresql://localhost:5432/eshop_ordering
username: postgres
password: postgresThe host creates its tables and collections at startup, unless wow.ddl says validate or none. The log and the snapshots are stored per aggregate type (wow_log__<context>__<aggregate>, wow_snapshot__<context>__<aggregate>). Named stores, wow.stores, split the data per aggregate instead: one aggregate's log on PostgreSQL, another's snapshots on Elasticsearch.
A system usually also runs the platform services, which are Wow services themselves: the ops service, which collects every service's parked aggregates and gives operators a console (The ops service and console); the view store, which keeps users' saved views; and the analytics catalog, which defines and publishes datasets.
Assumptions
The design rests on a few assumptions about the environment. A deployment that breaks one of them breaks a guarantee.
- One cluster. All the services of a system run in the same cluster and can reach each other's internal ports directly. A wait that crosses into another service is signalled by that service's nodes straight to the node the command came from.
- Synchronized clocks. Leases expire by the nodes' clocks. The clock skew between nodes must be far below the lease time to live, 10 seconds by default.
- One tenant space. All the contexts of a system share one set of tenant ids. A tenant id crosses services as it is, in commands, published streams, receipts and timers, so every service must resolve a caller's tenant the same way.
- Adjacent versions. During a rolling upgrade, the nodes of a service may run two adjacent minor versions of the same major version, and no wider range. A major version upgrade is a blue-green switch.
- A fixed partition count. A context's partition count cannot change once its log holds entries. It must be a power of two that divides 4,096. Choose it before the first deployment; 64 suits most services.
Starting and stopping
A node opens its public port only once it has started: its backends are up, its internal port is bound and it has joined the members. It stops in the reverse order:
- Readiness reports that the node refuses traffic, and the public server stops taking requests. Waits still open finish, within
wow.wait.max-timeout(60 seconds). A request still open 2 seconds after that, one whose body or whose reader stalls, is cut: the server closes its connection. A query stream ends at once withnode-stopping, and one cut instead ends without itsendevent: either way its client resumes it withLast-Event-ID. - The node stops taking commands for its partitions, finishes those in flight within
wow.cluster.drain-timeout(10 seconds), stops its subscriptions withinwow.subscription.stop-timeout(10 seconds), saves their checkpoints and releases its leases. Other nodes take the partitions over. Every partition is handed off at once, so these bounds hold for the whole node, whatever the number of partitions it owns; the releases run at mostwow.cluster.lease-parallelism(16) at a time. - The internal port closes last, with the connections still open on it.
Unless spring.lifecycle.timeout-per-shutdown-phase is set, the host sets Spring Boot's shutdown phase to the node's stop bound (ServiceNodeOptions.stopBound): max(wait.max-timeout, 2 × subscription.stop-timeout + cluster.drain-timeout) + 3 × cluster.drain-timeout, 90 seconds by default. A shorter phase set by the application is kept, with a warning when the node starts. The public server's graceful shutdown comes before it, in a phase of its own, and lasts as long as its longest request, up to wow.wait.max-timeout and 2 seconds; then the server's stop cuts what is still open, within Reactor Netty's 3 seconds. Give the platform's termination grace period at least the preStop pause, that wait and the node's phase, with a margin for those few seconds; Wow's chart derives it so, its margin 15 seconds, 170 seconds by default (Kubernetes).
With Spring Boot Actuator on the classpath, the host contributes the node's health to the readiness and liveness groups:
startupProbe:
httpGet:
path: /actuator/health/readiness
port: http
periodSeconds: {{ .Values.probes.startup.periodSeconds }}
failureThreshold: {{ .Values.probes.startup.failureThreshold }}
readinessProbe:
httpGet:
path: /actuator/health/readiness
port: http
periodSeconds: {{ .Values.probes.readiness.periodSeconds }}
failureThreshold: {{ .Values.probes.readiness.failureThreshold }}
livenessProbe:
httpGet:
path: /actuator/health/liveness
port: http
periodSeconds: {{ .Values.probes.liveness.periodSeconds }}
failureThreshold: {{ .Values.probes.liveness.failureThreshold }}- Readiness fails until the node runs, while its log, a store its writes need (a type's own snapshot store) or its lease store is down, while it owns none of its share of partitions past a hand-over grace period, or while a topic it reads is still joining.
- Liveness fails only when the node is stuck: its dispatcher or its commands make no progress while its stores answer. It never fails for a storage outage, and not while the node drains, so an outage does not restart every node at once.
Standby for a migration's cut-over
Through the dual-run window of an online 9.x cut-over, migrate-data tail imports what 9.x keeps writing while the V10 service serves reads. Start its nodes with wow.node.standby: true:
- They serve state reads and queries of what the tail imports.
- They report ready (
/actuator/health/readinessisUP, with their lease groups and topics markedstandby), so the load balancer sends them those reads. - They refuse every command with
wow.node.standby(503), so nothing writes to V10 before the cut-over. - They join no lease group: no subscription handles anything, no parked entry is retried, no job or schedule runs. A saga or a reactor that starts at the end of its stream starts where the stream ends at the activation, so it never acts on the imported 9.x history.
At the cut-over, once 9.x has stopped and the final pass, compare and snapshot have run, activate each node on its internal port, naming the node's service in Wow-Service. The body names who activates it and why, for the audit:
curl -X POST "http://<node>:9090/wow/node/activate" \
-H "Wow-Service: <the node's service>" -H "Content-Type: application/json" \
-d '{"by": "<operator>", "reason": "cut-over <ticket>"}'The node joins its lease groups and starts its subscriptions, its parked-entry retries, its jobs and its snapshot maintenance. It admits commands from when it starts to join, as a node that starts does: a command of a partition it does not own yet goes where any node's goes, so its own handlers are not refused as their partitions start. It answers its standby status, standby: false, activatedAt, activatedBy and reason, and logs the same at WARN.
GET /wow/node/standby, with the same header, answers that status at any time. Activating a node that is not on standby changes nothing and answers when it was activated. Both routes are taken only from the node's own service: without the header they answer 401, from another service 403. Activate every node of the service: one left on standby keeps refusing commands and takes no partition.