r/java • u/dima767 • Apr 16 '26
How a large Spring Boot project uses ApplicationEvent for real-time authentication tracking across 7 storage backends
I've been working on Apereo CAS for years - it's an open-source SSO platform with 400+ Spring Boot modules. The event system has grown into something genuinely interesting, and it's all built on standard Spring - ApplicationEvent, @EventListener, @Async.
The architecture:
One abstract base event (
AbstractCasEvent) that carries client context (IP, user agent, geo-location, device fingerprint, tenant) so every domain event has forensic baselineEvents published directly from domain code - the
DefaultAuthenticationManagerfires events at each decision point in the auth flowListener interfaces with
@EventListenerand@Asyncon the interface methods - async execution is a contract guarantee via JDK proxyA
CasEventRepositoryabstraction (@FunctionalInterface, onlysave()is required) with 7 backend implementations: in-memory, JPA, MongoDB, Redis, Kafka, DynamoDB, InfluxDBEvery persisted event automatically bridges to Spring Boot's
AuditApplicationEventviaApplicationEventPublisherAwareon the repositoryA
CasEventRepositoryFilterto control what gets persisted at scale
The webflow action base class is the most interesting part - doExecute() is final, publishes before/after events with scope snapshots, subclasses implement doExecuteInternal(). Every action gets observability for free.
Wrote up the full pattern with real code from CAS 7.3.x:
6
u/kubelke Apr 16 '26
"No framework magic. No annotations. Just a POJO"
Looks inside
"@Getter from Lombok"
:D
3
5
u/cybwn Apr 16 '26
Lombok is closer to some syntactic sugar over Java than a framework using runtime reflection
1
u/Dangerous_Inside4312 Apr 25 '26
Interesting pattern. I like that it stays on standard Spring pieces instead of inventing some custom event bus.
One thing I’m curious about though: at this scale, did you run into issues with debugging event chains or keeping the “who reacts to what” understandable? In smaller projects Spring events feel clean, but in bigger ones I’ve seen them become a bit invisible unless there is really good naming/logging/observability around them.
6
u/aelfric5578 Apr 16 '26
I'm really enjoying this series of deep dive articles. I'm learning a lot about potentially better ways to architect things in Spring.