This repository contains the source code for a Proof of Concept (PoC) developed as a hands-on study of Go (Golang) applied to a microservices architecture. The goal is to simulate a real-world environment, covering essential concepts to prepare for backend technical interviews.
In the current phase, the architecture consists of three microservices and their messaging infrastructure, all running as Docker containers and orchestrated locally by Docker Compose.
graph TD
subgraph "Client"
A[Postman / cURL]
end
subgraph "Docker Network"
B[orders-service]
C(RabbitMQ)
D(Kafka)
E[notification-service]
F[analytics-service]
end
A -- HTTP POST :3000 --> B
B -- Publishes Message --> C
B -- Publishes Event --> D
C -- Delivers Message --> E
D -- Delivers Event --> F
orders-service: A REST API that receives orders. It publishes a command to RabbitMQ and an event to Kafka.notification-service: Consumes from the RabbitMQ queue to "send" notifications.analytics-service: Consumes from the Kafka topic to log events for analysis.
- Go (Golang): The language used for building all microservices.
- Docker: Used to containerize each microservice and the infrastructure.
- Docker Compose: The local orchestrator to define, build, and run the entire multi-container application with a single command.
- RabbitMQ: The message broker for asynchronous, command-based communication (queues).
- Kafka: The event streaming platform for an event-driven architecture.
- Dockerfile: Used with multi-stage builds to create optimized, small, and secure Go images.
With the entire application defined in Docker Compose, running it has been simplified to a single command.
- Go (version 1.18 or higher) installed (for IDE support).
- Docker and Docker Compose installed and running.
git clone https://github.com/felipedmsantos95/go-microservices-poc
cd go-poc-microsservicosKafka in KRaft mode requires a unique cluster ID. You can generate one with the following command:
docker run --rm confluentinc/cp-kafka:latest kafka-storage random-uuidCopy the generated ID and paste it into the docker-compose.yml file, replacing the value for CLUSTER_ID.
Execute the following command in the project's root directory:
docker-compose up --build- The
--buildflag tells Docker Compose to build your Go services' images from theirDockerfilesbefore starting the containers.
Docker will build the three images, start all five containers (3 services + Kafka + RabbitMQ), and display the logs from all of them in your terminal.
Send a POST request to the orders-service.
curl -X POST http://localhost:3000/orders \
-H "Content-Type: application/json" \
-d '{
"product": "Go Book",
"quantity": 2
}'Observe the terminal where docker-compose is running. You will see interleaved logs:
- From
orders-service, confirming the order was received. - From
notification-service, confirming the message was received from RabbitMQ. - From
analytics-service, confirming the event was received from Kafka.
To stop and remove all containers, press Ctrl + C in the terminal, then run:
docker-compose down -v- Phase 1: Create the first microservice (REST API).
- Phase 2: Asynchronous communication with RabbitMQ.
- Phase 3: Event-driven architecture with Kafka.
- Phase 4: Full application containerization with Docker and Docker Compose.
- Phase 5: Deploy the entire architecture to Kubernetes.