Microservices

Eventuate

Eventuate is a framework that makes event-driven microservices easy. It simplifies a lot our work, as it has change data capture(CDC), message broker(Kafka) and a event store (Eventuate). For more information regarding eventuate you can start with this. 

Now let’s apply this on our known use case(items and bids). First of all, a picture will offer an high level view of what we have.

bid_cqrs

The same structure will apply for items.

item_cqrs

An a important thing to remember. The event store is the same; this is the way services will communicate with each other.

store_cqrs

The use case is pretty straight-forward. An item will be created, triggering an item created event. This event will update the items materialized view. Multiple bids will be made, triggering multiple bid events which will  update the bids materialized view. Bids will be evaluated, that means the corresponding item will be updated through an item updated event; and of course the items view will be updated again.

Everything is deployed in docker containers. If you are on OSX like me you need to do this first. After running

ip

you should be able to run docker (the ip is the one I’ve used, you can choose another fi you want).

These will be build using docker compose.

up

After the containers are up are running just run docker ps to see the processes.

Let’s do some http calls. First of all we create an item.

create_item

Check the items.

get_items

Next, some bids on the item.

create_bid1

create_bid2

create_bid3

Check the bids.

get_bids

Evaluate the bids.

winning_bid

Check the bids.

get_bids2

Cool, pretty straightforward.

One drawback of CQRS is that you need to split the microservice in command and query which makes two component to maintain. Some of you will think this is a distributed monolith. But overall it’s a clean solution: commands -> events -> queries.

SOURCE CODE

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s