'Can we use Event-driven without CQRS
I have experience with Event-driven for less than 1 year and there's something that I don't really understand that why do we need it. As my tiny brain can remember, CQRS help us separate command model (write) / query model (read) so we can easily design database for write and read. It sounds good, but it has some consistency problem between write and read timeline or also known as set based consistency and how do I make sure if there's no error between the timeline or if it occurs how do I even make sure if the current read model is valid?. So I start asking myself do I really need CQRS. Can't I just use Event-driven without it and focusing on how the event are stored. So I came up with something like this.
public class UserController {
@PostMapping
public CompletableFuture<String> createUser(request: RegisterUserRequestDTO){
// some validation and business logic here
// publish event if succeeded
publisher.publish(UserRegisteredEvent.create(request));
}
}
class UserEventHandler {
public void handle(event: UserRegisteredEvent){
// save data to the db here or the read model
}
}
So I haven't tried it yet, but it seems to work maybe? So I'm a stupid guy with less experience anyway so correct me if i'm wrong. why do we need CQRS combine with Event-driven? Can I use Event-driven without CQRS? What's the idea behind it.
Solution 1:[1]
CQRS and event-driven are two totally different patterns that can very successfully be applied and used on its own.
But together with DDD the fit very well together!
Visit CQRS.NU where you can find one implementation of this that you can take a look at.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Tore Nestenius |

