Skip to content

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

License

Notifications You must be signed in to change notification settings

felipedmsantos95/go-microservices-poc

Repository files navigation

Leia a versão em Português

PoC - Microservices with Go, RabbitMQ, Kafka, and Kubernetes

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.

🏛️ Architecture (Phase 4 - Docker Compose Orchestration)

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
Loading
  1. orders-service: A REST API that receives orders. It publishes a command to RabbitMQ and an event to Kafka.
  2. notification-service: Consumes from the RabbitMQ queue to "send" notifications.
  3. analytics-service: Consumes from the Kafka topic to log events for analysis.

🛠️ Tech Stack

  • 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.

🚀 How to Run the Project (Phase 4)

With the entire application defined in Docker Compose, running it has been simplified to a single command.

Prerequisites

  • Go (version 1.18 or higher) installed (for IDE support).
  • Docker and Docker Compose installed and running.

1. Clone the Repository

git clone https://github.com/felipedmsantos95/go-microservices-poc
cd go-poc-microsservicos

2. Configure Kafka Cluster ID

Kafka 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-uuid

Copy the generated ID and paste it into the docker-compose.yml file, replacing the value for CLUSTER_ID.

3. Run the Entire Application

Execute the following command in the project's root directory:

docker-compose up --build
  • The --build flag tells Docker Compose to build your Go services' images from their Dockerfiles before 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.

4. Test the Application

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
}'

5. Check the Result

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.

6. Stop the Application

To stop and remove all containers, press Ctrl + C in the terminal, then run:

docker-compose down -v

📈 Next Steps

  • 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.

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published