🚨🚨 Spring Boot developers I need your opinion on a production problem
🚨 **Spring Boot developers — I need your opinion on a production problem**
I’m working on a Spring Boot application with **JPA + PostgreSQL + Kafka**, and I’ve hit a problem that took me way deeper than I expected.
Imagine this:
```java
@Transactional
public void createOrder(Order order) {
orderRepository.save(order);
applicationEventPublisher.publishEvent(
new OrderCreatedEvent(order.getId())
);
}
```
The event listener then publishes the event to Kafka:
```java
@Async
@TransactionalEventListener(
phase = TransactionPhase.AFTER_COMMIT
)
public void handle(OrderCreatedEvent event) {
kafkaTemplate.send("orders", event.orderId());
}
```
At first glance, everything looks fine.
But here's the problem:
Sometimes the Kafka event **isn't published**, even though the order was successfully created.
And if the application crashes at the wrong moment, we can end up with:
Database ✅
Kafka ❌
Now I'm wondering:
👉 Would you use **Transactional Outbox** here?
👉 Is there another Spring-native approach you'd prefer?
👉 How would you guarantee that the database state and Kafka event don't get out of sync?
I'm specifically interested in how you'd solve this in a **real production system**, not just theoretically.
1
2 comments
Mourad Zerbane
3
🚨🚨 Spring Boot developers I need your opinion on a production problem
Amigoscode
skool.com/amigoscode
A free learning community led by Nelson Djalo. Master Programming & AI, get updates, and grow in a fast-moving industry.
Powered by