How does a subscription query deliver live updates to a client without polling?
A subscription query stays open after returning its initial result and relies on the same event-handling pipeline that already keeps a projection's read model up to date. When a tracking event processor delivers a new event to the projection's existing @EventHandler and that handler updates the read model, Axon checks whether any open subscription queries are currently watching that same piece of data and, if so, pushes the freshly updated result directly to them. On the server side, this is typically exposed as a reactive stream — such as a Flux over Server-Sent Events — combining the initial result with a continuous stream of subsequent updates. Because it piggybacks entirely on the projection's existing event handling, no new event-handling code needs to be written specifically to support live updates; it's a capability that comes essentially free once the projection already exists.
Ready to master this question?
Generate a complete walkthrough — background, the full answer in plain language, a working code example explained line by line, a real-world scenario, common mistakes, and how this same question gets asked in different ways.
Sign in to generate a response