Scrivio Interview library
ScenarioAdvanced7 min read · updated 12 November 2026

Many modules in your services react to in-process Spring application events. A team proposes replacing all of them with Kafka topics for consistency. How do you decide?

In-process Spring events are simple and fast and can take part in the publisher's transaction, but they live only in memory and are lost if the process crashes before they are handled. Kafka gives durability, replay and consumers in other services, at the cost of running a cluster and accepting eventual consistency. So we do not replace everything for consistency's sake: we use Kafka, published reliably through an outbox, where consumers are in other services or the reaction must survive crashes, keep in-process events for reactions inside the same module or service, and document which events are internal and which are integration contracts.

Why this question is asked

Proposals to standardise on one mechanism are attractive because they promise one way of doing things. But events inside a service and events between services solve different problems, and forcing one tool onto both makes at least one of them worse. Interviewers give this scenario to senior engineers because it is a judgment call with real trade-offs in latency, reliability, operations and team autonomy, and because the right answer is usually a rule for choosing, not a winner. In this answer, we will compare what each mechanism guarantees, look at what moving an internal event to Kafka actually costs, set the decision rule, make the Kafka side reliable with an outbox, and finish with how to document the boundary.

1What In-Process Events Give Us

A Spring application event is a method call with indirection. The publisher calls publishEvent, and Spring calls each listener, by default synchronously in the same thread. That makes it cheap, microseconds rather than milliseconds, easy to debug with a single stack trace, and easy to test without any infrastructure. A listener can run inside the publisher's transaction, or after its commit with @TransactionalEventListener, so a reaction can be atomic with the change that caused it.

The limit is that the event exists only in the memory of one JVM. If the process crashes between the commit and the listener running, or the listener is @Async and its queue is lost on shutdown, the event is gone. There is no replay, no history and no way for another service to subscribe. Spring Modulith's event publication registry narrows this gap by persisting events, if a project uses it.

2What Kafka Gives and What It Costs

Kafka stores events in durable, replicated, ordered logs called topics. Consumers read at their own pace and track their position, so a consumer that was down catches up when it returns, and a new consumer can replay history from the start of the retention period. Any service in the company can subscribe, which makes Kafka the natural backbone for events between services.

Those properties have costs. Every event now crosses the network and is serialised, so a reaction that took microseconds takes milliseconds or more. The reaction happens later, in another transaction, so the system becomes eventually consistent: for a short time the order exists and the stock is not yet reserved. We need schemas and compatibility rules for event formats, consumer groups, retries, dead-letter topics, monitoring of lag, and someone running the cluster. Testing needs a broker or Testcontainers. And publishing to Kafka from a database transaction has its own trap: the database can commit and the Kafka send fail, or the other way round.

In-process events compared with Kafka
PropertySpring application eventsKafka topics
LatencyMicroseconds, same threadMilliseconds, over the network
TransactionCan join or follow the publisher'sSeparate; eventual consistency
Survives a crashNo, memory onlyYes, replicated log
Replay and historyNoneWithin retention
Consumers in other servicesNot possibleYes, any consumer group
Operations and testingNone beyond the appCluster, schemas, lag, Testcontainers

3The Decision Rule

Rather than choosing one tool for everything, we ask two questions about each event. Does a consumer live in another service, or is one likely to soon because it is a business fact other teams care about? And must the reaction survive a crash of the publishing process? If either answer is yes, the event belongs on Kafka. If both are no, the reaction is internal to the module or service, and an in-process event is simpler, faster and easier to keep correct.

Take three examples. OrderPlaced is needed by billing, shipping and analytics, which are separate services: Kafka. Clearing a local cache when a product is updated in the same service only matters while that process is running, and if it crashes the cache is gone anyway: in-process. Recalculating a customer's loyalty tier inside the same service must not be lost, but has no outside consumer: an in-process event persisted by an outbox or the Modulith registry, or simply a direct call in the same transaction.

Step throughChoosing the mechanism for one event
  1. Is there a consumer in another service?Now or clearly expected
    YesPublish to Kafka through an outboxNoNext question
  2. Must the reaction survive a crash?Losing it would be a business error
    YesPersist it: outbox or publication registryNoNext question
  3. Keep an in-process eventSame module or service, simple and fast

3 steps in order. Play them, or step through them one at a time.

4Publishing to Kafka Reliably

For the events that do go to Kafka, a direct kafkaTemplate.send inside a @Transactional method is not reliable. If the send succeeds and the transaction then rolls back, other services see an event for something that never happened; if the commit succeeds and the send fails, they never hear about it. The transactional outbox avoids both: we write the event to an outbox table in the same database transaction as the change, and a relay, either a polling worker or change data capture such as Debezium reading the database log, publishes it to Kafka afterwards. Delivery is then at least once, so consumers must be idempotent, for example by recording processed event ids.

This is worth saying in the review of the proposal: replacing in-process events with direct Kafka sends would make several flows less correct than they are today, not more.

Java
@Transactional
public void placeOrder(OrderRequest req) {
Order o = orders.save(Order.from(req));
events.publishEvent(new StockToReserve(o.getId())); // internal: same service
outbox.save(OutboxEvent.of("orders.v1", o.getId(), OrderPlaced.from(o))); // integration contract
}
// commit -> internal listener ran in the same transaction; relay later sends OrderPlaced to topic orders.v1

5Documenting Internal Events and Integration Contracts

The deeper value of the proposal is the wish for consistency, and we can deliver that without moving everything. We classify every event as internal or integration. Internal events are implementation details of a service; they can be renamed or removed freely, and they stay in-process. Integration events are public contracts: they have a schema in a registry, a version in the topic or schema name, an owning team, compatibility rules such as only adding optional fields, and documentation of what they mean. They go through Kafka via an outbox.

We write the decision rule and the two classes into the engineering guide, give each service a short list of its integration events, and add a review check: a new Kafka topic needs a named consumer outside the service, and a new in-process event must not be consumed by another module's database tables. That gives teams one consistent way of deciding, which is the consistency that actually matters.

6Follow-up questions

Is it not simpler to run everything on Kafka so there is only one tool?

It is one tool but not one problem. Internal reactions would gain network latency, eventual consistency, schema management and broker dependency for no benefit, and tests would need a broker. Consistency of the decision rule gives most of the benefit with much less cost.

What if an internal event later gets an external consumer?

Then we promote it: define a proper integration event with a schema and version, publish it through the outbox, and keep the internal event if internal listeners still use it. We do not expose internal event classes directly, because that would freeze implementation details into a contract.

How do you keep in-process events from becoming a hidden mess?

We keep them inside module boundaries, name them clearly, and avoid long chains where one listener publishes another event. Tools like Spring Modulith can verify that modules only interact through declared events and APIs, which keeps the event flow visible.

7Conclusion

In this answer, we compared in-process Spring events, which are simple, fast and transactional but lost on a crash, with Kafka, which is durable, replayable and shared across services but costs operations and eventual consistency. The rule is to use Kafka through an outbox when consumers are in other services or the reaction must survive a crash, to keep in-process events for reactions inside one service, and to document which events are internal and which are integration contracts.

What to say in the interviewAbout 90 seconds aloud

Open with

I would not replace everything with Kafka just for consistency, because the two mechanisms solve different problems. In-process Spring events are essentially method calls with indirection: microseconds, one stack trace, easy to test, and they can run inside or right after the publisher's transaction.

Then, if they want more

Their weakness is that they live in memory, so a crash before the listener runs loses the event, and no other service can consume them.

Kafka gives durable, replicated topics, replay within retention, and consumers anywhere in the company, but every event crosses the network, reactions become eventually consistent, and we take on schemas, consumer lag, retries, dead-letter topics, a cluster, and the dual-write problem between the database and the broker. So I would set a rule per event.

If a consumer lives in another service, or the reaction must survive a crash, it goes on Kafka, published through a transactional outbox so the event and the database change commit together, with idempotent consumers. If it is a reaction inside the same module or service, like refreshing a local cache, it stays an in-process event.

Then I would make the boundary explicit: integration events are public contracts with a schema, a version and an owner, and internal events are implementation details that can change freely. That gives teams one consistent way of deciding, which I think is the consistency the proposal is really after.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Many modules in your services react to in-process Spring application events. A team...": https://scrivio-interview-library.netlify.app/java/behavioral-patterns/1002a813c2/