Search code examples
microservicesserver-sent-events

How to fill microservice from non-event sourced system?


We currently have a monolithic system running, which we are looking into splitting into a microservice archietcture. We are also looking to adopt event sourcing.

My problem is that all articles and videos I can find, describes the same approach to booting a new service into an already existing microservice arhitecture; Run all the events through your new service and it will end up in the right state.

My problem is that that solution covers a new microservice in an already event-sourced system and not a new microservice in an already monolithic architecture (i.e. we do not have any events to boot from).

I have considered some solutions (like exposing an api from the monolith or letting the microservice boot from a datadump from the monolith DB), but I'm having a hard figuring out what other people have done in this situation, so my question is;

Are there any "best-practice" solutions/strategies to boot a microservice from a monolith that is not event-sourced?


Solution

  • I'll start by saying that this is not an easy task. There is a lot to do before you get into the coding part. And I'll be honest, this is not something that is usually done. Event Sourcing is a pattern that should be applied from the very beginning: migration is hard, complex and painful.

    Since you have a monolith to start with, you first have to define which Bounding Contexts you have. This will help split the codebase (although, to be fair, might not be a great idea. But that's out of scope).

    Once you have identified them, you have to start defining which "events" you have in each microservice. And these have to be very specific, so avoid doing things like "user updated" or "button clicked". But rather do something like "email changed" or "order placed". In a nutshell, events have to talk about Domain concepts.

    Now, going back to your original question, you can most likely consider your current state as "snapshots" at T0. You could use a special kind of event, something like "user initialized", which would basically contain all the necessary payload to bootstrap your entities.