Introduction
EventStoreDB is a database that allows users to read and persist events into fine-grained streams while also accessing all or a subset of events. It is a database designed for event sourcing. Its designed from the ground up for Event Sourcing and provides an unequalled solution for developing event-sourced systems.
What is an Event, Event Stream, Event Sourcing and EventStoreDB
Event
An event is a significant occurrence for the system. An event can be either a user action or a change in system state, such as when a user double-clicks on a taskbar icon to launch a new application or when the file system crashes due to memory exhaustion.
Events used to describe the specific business reality in the past tense. For instance, “InvoiceIssued” indicates that the invoice’s status has really changed as opposed to simply existing.
When it comes to event sourcing, an event typically comprises distinctive metadata, such as the timestamp of the event, the subject’s unique identify, etc.
Event Stream
An event stream is a sequence of immutable and append-only events. You can loop through all the events in your database by using the EventStream function, which accepts an event object as a parameter and returns an EventStream instance. Event streams, which provide the whole history of the modifications, serve as the domain object’s source of truth. By reading every stream event and applying each one in the order they appeared, you may obtain state.
A stream need to have a distinctive identity that corresponds to the particular item. Each event occupies a certain space inside the stream. Typically, a numerical, incremental number gets used to indicate this location. This number gets used to specify the sequence of actions during state retrieval. It may also be employed to identify concurrency problems.
Event Sourcing
Event sourcing is an architectural pattern based on the idea of storing events in an append-only log as a source of truth.
It is an alternative method of data persistence. Event Sourcing stores each state mutation as a separate record known as an event as opposed to state-oriented persistence, which only retains the most recent version of the entity state.
Lets Consider an example :
To illustrate this idea, lets imagine that we’re selling something and many times during a single sale, we’re are going to need to know the status of our order. Traditionally, we would use an ORM and query an object by its ID. The ORM will go to the relational database and get the necessary state then populate an object hierarchy with it. In the end, we will get back the object including its child objects completely loaded with state from the database.
When Event Source model gets populated differently. To get the details of an order, we query for all the domain events for that specific order ID and then apply each of the events one by one to the order model. Once all the events gets applied the state of the order is up to date and we can get whatever details that we want from it.
Benefits of Event Sourcing
Audit : One of the best solutions for an audit log is an event-sourced system, which maintains your data as a stream of impermanent events across time.
Time travel : Moving systems backwards and forwards in time is feasible since all state changes gets preserved, which is incredibly helpful for debugging and “what if” research.
Root cause analysis : The ability to link business events back to their original events allows for complete process visibility and traceability.
Fault tolerance : Fundamentally, event streams are simply logs with superior backup and recovery capabilities. It is possible to reconstruct downstream forecasts by writing just the essential “source of record” data to the event stream. A distributed database solution called EventStoreDB has failover in the event of a leader failure.
EventStoreDB
The Event Store is a database server that can store streams of events in succession. It enables you to efficiently query this data if necessary. The essential element of Event Store is an event stream, which is a collection of events that occur in chronological order under one name and are identifiable by GUID.
The fundamental advantage of utilising EventStoreDb as your main data storage system is that it offers far greater flexibility than other databases do:
No schema specification is necessary. There are no restrictions on the number of tables or fields per table, or on the size of the columns, so you may build as many tables as you need in your database.
Conclusion
In this blog, we got to know about what an Event is, what is an EventStream, what is Event Sourcing. We also went through EventStoreDb and the benefits of Event Sourcing. Stay Tuned.
For more information refer to : https://developers.eventstore.com/server/v21.10/#getting-started
For more Blogs on latest technologies refer to : https://blog.knoldus.com/