Building Microservices Event Bus and REST api (python / flask)

Background

I’m building my first application using a microservice architecture. I’ll be working mostly in Python using Flask.

I’m considering implementing an event/message bus to coordinate actions between services. A few services that I intend to implement are: Auth, Users, Posts, and Chat. The application has two entities (‘User’, and ‘Group’) that are used by almost every service. I have a separate database for each service, and each database has it’s own users and groups tables to manage the user/group data specific to that service. Now, when I think about an event like creating a new user, each service will need to create a new entry in the users table, which is why I’m considering using an event bus.

I read this post which discusses CQRS and using HTTP (REST) for external communication between services, while using an event bus for internal communication. Services process (HTTP) requests, and emit events about data changes (e.g. the creation of a new User by the Auth service). Other services consume the events which may trigger other processes (and more events).

Question

Where I’m hung up is how to actually implement (in Python) a service which listens for both HTTP requests, and for new events in a set of subscribed channels. I get that you need to use a tool like redis/rabbitMQ, but is it possible to handle both types of requests in the same process, or do you need to run two servers (one for REST requests and the other for event handling)?

Also, if you have any comments on the general approach/architecture described above, I’m all ears.

Add Comment
0 Answer(s)

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.