Asynchronous Processing with Go using Kafka and MongoDB
In my previous blog post “My First Go Microservice using MongoDB and Docker Multi-Stage Builds”, I created a Go microservice sample which exposes a REST http endpoint and saves the data received from an HTTP POST to a MongoDB database.
In this example, I decoupled the saving of data to MongoDB and created another microservice to handle this. I also added Kafka to serve as the messaging layer so the microservices can work on its own concerns asynchronously.
In case you have time to watch, I recorded a walkthrough of this blog post in the video below :)
Here is the high-level architecture of this simple asynchronous processing example wtih 2 microservices.
Microservice 1 — is a REST microservice which receives data from a /POST http call to it. After receiving the request, it retrieves the data from the http request and saves it to Kafka. After saving, it responds to the caller with the same data sent via /POST
Microservice 2 — is a microservice which subscribes to a topic in Kafka where Microservice 1 saves the data. Once a message is consumed by the microservice, it then saves the data to MongoDB.
Full article in my website
https://www.melvinvivas.com/developing-microservices-using-kafka-and-mongodb/