Search code examples
apache-kafkaarchitecturerabbitmqmicroservicesevent-driven

How can event-driven architecture be applied to this example?


I am unsure how to make use of event-driven architecture in real-world scenarios. Let's say there is a route planning platform consisting of the following back-end services:

  • user-service (manages user data and roles)
  • map-data-service (roads & addresses, only modified by admins)
  • planning-tasks-service (accepts new route planning tasks, keeps track of background tasks, stores results)

The public website will usually request data from all 3 of those services. map-data-service needs information about user-roles on a data change request. planning-tasks-service needs information about users, as well as about map-data to validate new tasks.

Right now those services would just make a sync request to each other to get the needed data. What would be the best way to translate this basic structure into an event-driven architecture? Can dependencies be reduced by making use of events? How will the public website get the needed data?


Solution

  • Cosmin is 100% correct in that you need something to do some orchestration.

    One approach to take, if you have a client that needs data from multiple services, is the Experience API approach.

    Clients call the experience API, which performs the orchestration - pulling data from different sources and providing it back to the client. The design of the experience API is heavily, and deliberately, biased towards what the client needs.

    Based on the details you've said so far, I can't see anything that cries out for event-based architecture. The communication between the client and ExpAPI can be a mix of sync and async, as can the ExpAPI to [Services] communication.

    And for what it's worth, putting all of that on API gateway is not a bad idea, in that they are designed to host API's and therefore provide the desirable controls and observability for managing them.

    Update based on OP Comment

    I was really interested in how an event-driven architecture could reduce dependencies between my microservices, as it is often stated

    Having components (or systems) talk via events is sort-of the asynchronous equivalent of Inversion of Control, in that the event consumers are not tightly-coupled to the thing that emits the events. That's how the dependencies are reduced.

    One thing you could do would be to do a little side-project just as a learning exercise - take a snapshot of your code and do a rough-n-ready conversion to event-based and just see how that went - not so much as an attempt to event-a-cise your solution but to see what putting events into a real-world solution looks like. If you have the time, of course.