Event sourcing persists domain objects as a sequence of (state changing) events. To load a domain object from an event store, an application must load and replay those events. Long-lived domain objects can potentially have a huge number of events, which would make loading them very inefficient.
The solution is to periodically persist a snapshot of the domain object’s state. The application only has to load the most recent snapshot and the events that have occurred since that snapshot was created.
The Eventuate API now supports a snapshot mechanism. To create snapshots for a domain object, you simply define a SnapshotStrategy in the Spring application context. A SnapshotStrategy defines two methods:
- possiblySnapshot() – invokes when an AggregateRepository updates an aggregate. It can decide to create a snapshot based on, for example, the number of events
- recreateAggregate() – recreates an aggregate from a saved snapshot
Currently, only Eventuate Local supports snapshots. Eventuate SaaS will support them soon. For more information, see Defining snapshot strategies in Java
We are super excited to announce that we have started migrating the example applications to the new Eventuate Java client. The highlights of this new client include:
- Open-source with Javadoc (still work in progress) and source jars
- Written in Java 8 instead of Scala with a Java wrapper
- Fully reactive
- Better modularity, which will make it easier to support more than just Spring applications
So far we have migrated the Money Transfer and the Customer and Orders examples.
For more information, please see the revised getting started guide.
It is a challenge to write a simple yet meaningful example application that illustrates how to develop event-driven microservices using the Eventuate platform. That is because the microservices architecture requires you to have at least two services. The Money Transfer application has, for example, three (soon to be at least 4) separate services. Even though it is a great example of how to write event-driven microservices using event sourcing and CQRS it is not the easiest introduction to the topic.
To make the getting started experience easier we have created the Todo List application. This application is a Java and Spring Boot application built using Eventuate™’s Event Sourcing based programming model. The application has a HATEAOS-style REST API for creating, querying, updating and deleting a todo list. The API design is inspired by the Todo backend project. The principle difference is that unlike the original version this API is eventually consistent.
The application has a CQRS-based architecture. Creates, updates and deletes are handled by the command side service, which consists of a Todo Aggregate that is persisted using event sourcing. Queries are handled by the query side service, which maintains a materialized view of the todo list in a SQL database.
There are two versions of the application. The simplest version is a single module Gradle project that builds monolithic version of the application of the API. It is a great way to learn the Eventuate API.
The other version of the application is a multi-module Gradle project, which can be deployed as either a monolith or as two microservices: a command-side service and a query-side service.
Both versions come with a Docker Compose file that can be used to launch the application along with a MySQL database.
To get started take a look at the README.md.
Learn more about Eventuate
To find out more about how you can use the Eventuate platform to build event-driven microservices:
We have released the early access version of the Eventuate Platform. It solves the distributed data management problems inherent in a microservice architecture. The platform provides a simple yet powerful programming model for writing event-driven microservices. It is based on the principles of Event Sourcing and Command Query Responsibility Segregation (CQRS).
It would be great if you could take a look and provide feedback to shape the future direction of the platform.
Matt Miller of Sequoia recently published a map of the microservices ecosystem.
The ecosystem map is very focussed on infrastructure. It lists many of the usual suspects including Docker, Kafka, Cloud Foundry, Azure, and Chef. It includes some developer frameworks such as Hystrix but unfortunately, the focus on infrastructure means there are some surprising omissions.
Microservices need a chassis
James Watters from Pivotal, for instance, points out that Spring Boot and Spring Cloud are nowhere to be seen:
That is a shame because if you are building microservices you need a microservice chassis, such as Spring Cloud + Spring Boot. A microservice chassis is a framework that enables you to quickly create a new service. It handles cross-cutting concerns such as logging, service discovery, service registration, externalized configuration, etc.
Microservices and distributed data management problems
Also absent from the microservices ecosystem map are technologies that make it easier for application developers to write the business logic, the raison d’être for the microservices. This is unfortunate since microservice patterns such as Database per Service have a profound impact on how business logic is written. It is often impossible to use the familiar ACID transaction model and instead developers must use BASE transactions.
The goal of the Eventuate platform is to to help application developers address these issues.
It provides a simple yet powerful event-driven, programming model that, among other benefits, solves the distributed data management problems inherent in a microservice architecture. The platform consists of a scalable, distributed event store server and client libraries for various languages and frameworks including Java, Scala, and the Spring framework. Eventuate makes it easy for application developers to implement eventually consistent transactions that span multiple microservices.
Towards a more comprehensive map of the microservices ecosystem
Microservices are more than than just infrastructure. You need a microservices chassis so that you can quickly create new services. Many microservice-based applications will benefit from using a platform such as Eventuate to solve distributed data management problems. Hopefully, the microservices ecosystem map will be expanded to reflect this reality.
Learn more about Eventuate
To find out more about Eventuate: