What is the problem?🤨
Every pattern have born from a problem. Actually we use patterns because they are accepted solutions for specific problems and they will help us not to stuck on same problems again when we encounter. Then let’s try to understand what is the problem behind the Event Sourcing Pattern.
Let’s think about you are developing a food ordering app that customers order food from restaurants and rasturants prepare these orders in the kitchen and deliver to the customers.
How you would handle orders? You need to deliver these orders from customer to the restaruant’s kitchen and cookers will see these orders eventually and start making them. On the other hand orders may not stay same like when they first made, customers might add new food or might change ingrediants.
When we look from microservice perspective you would create a OrderService and a RestaurantService. You would create the order in the OrderService and send it to the RestaurantService in some way for example by using event queue. The best way handling changes on the orders would be using events, for example when order created OrderCreated event will be created and architecture would look like below.