How does real-time data processing interact with event sourcing?

July 10, 2023

Tags: Technologies

event sourcing


One of the topics we will be covering at our annual event, which will be held on September 21 in Panama City, is event sourcing, a software architecture that many people are unfamiliar with but that has numerous benefits when implemented in a software product.


Event sourcing, also known as data supply in Spanish, is an architectural style that saves an application's state as a sequence of events. Instead of keeping an object's current state, event sourcing records any changes or events that have occurred over time.


The program can reconstitute the present state of the object at any time by replaying these events. This pattern provides a trustworthy and auditable record of how the application's state has changed over time.



event sourcing


How does real-time data processing work?


Real-time data processing and event sourcing are two principles that can be used to create robust and scalable systems. You must first understand real-time data processing and how it relates to event sources.


The ability to evaluate and act on data as it is generated, offering immediate insights and reactions, is referred to as real-time data processing. It entails analyzing and responding to data in near real time or with little delay. This is especially critical in cases where judgments or actions must be taken quickly based on incoming data streams.


Let's have a look at how real-time data processing can be integrated with event sourcing:


  • Event Capture: The primary data in an event sourcing system is events. These events can be recorded from a variety of sources, including user interactions, system events, sensors, and third-party services. After that, the events are saved in an event log or event store.
  • Event Processing: As new events are recorded, they can be processed in real time to acquire insight or to initiate urgent action. Real-time event processing systems can subscribe to the event stream and respond to specific occurrences through the execution of relevant logic. Aggregations, filtering, enrichment, and interaction with other systems are all examples of processing.
  • Event store update: After processing real-time events, the resulting modifications can be applied to the event store. This guarantees that the event storage represents the application's current state after processing the most recent events. These updates may involve the creation of new events, the modification of current events, or the inclusion of new information to events.
  • Real-time data processing allows you to access the event store for the present state of objects or analyze previous data. To obtain real-time changes, applications can subscribe to certain event kinds or patterns. Complex Event Processing (CEP) approaches can be used to detect patterns or anomalies in event flow.


You may develop systems that not only provide immediate insight and action, but also keep a reliable history of how the system's state has evolved over time by combining real-time data processing with event sourcing. This can be useful in fields such as banking, logistics, IoT, and many others where auditing, traceability, and historical analysis are required.


event sourcing


Putting event sourcing to use in the real world


The usual method in a financial application, for example, is to have a database; when a transaction is to be made, the program connects to the database, reads the account statement, and applies the changes as income or withdrawals.


With event sourcing, this process is not handled with the current state, but everything is derived in events. For example, instead of going to the database and modifying the account, the system issues an event with the details of this transaction, and the systems "interested" in this event will react and process the transaction.


Each transaction is classified as an event, and the program will explore each event to, for example, see the history of an account. It may appear to be extra effort, but the firm or client will have a history of everything that occurred as a security mechanism in case the database fails.


We recommend you on video