A production-ready, event-driven microservices architecture for peer-to-peer rental platforms, built with NestJS, Kafka, and Docker.
This project is a robust boilerplate for building scalable, maintainable, and cloud-ready peer-to-peer rental platforms. It leverages:
- BFF (Backend For Frontend) Layer: Central API gateway for authentication, routing, and orchestration.
- Domain-Driven Microservices: User, Product, and Feedback services, each with its own database and business logic.
- Event-Driven Communication: Powered by Kafka for decoupled, resilient messaging.
- Polyglot Persistence: Each service can use the database best suited for its needs (Postgres, MongoDB, Elasticsearch, etc.).
- Dockerized Databases: Easy local development and zero-cost infrastructure.
flowchart TD
FE[Frontend]
BFF["BFF Layer - NestJS"]
USER["User Microservice"]
PRODUCT["Product Microservice"]
FEEDBACK["Feedback Microservice"]
POSTGRES[("Postgres DB")]
ELASTIC[("Elasticsearch")]
MONGO[("MongoDB")]
FE -->|HTTP| BFF
BFF -->|Kafka| USER
BFF -->|Kafka| PRODUCT
BFF -->|Kafka| FEEDBACK
USER --> POSTGRES
PRODUCT --> ELASTIC
FEEDBACK --> MONGO
- BFF Layer: Handles all HTTP requests, authentication, and hides microservices from the frontend.
- Microservices: Each service listens to Kafka topics, processes messages, and manages its own data.
- Kafka: Central message broker for asynchronous, decoupled communication.
- Databases: Each service uses the most suitable database for its domain.
- 🔒 Security: BFF pattern ensures microservices are never exposed directly to the frontend.
- 🧩 Modularity: Each service is independent, making it easy to extend or replace.
- ⚡ Performance: Kafka enables high-throughput, low-latency communication.
- 🛠️ Polyglot Persistence: Use the best database for each domain (Postgres, MongoDB, Elasticsearch).
- 🐳 Zero-Cost Local Dev: All infrastructure (Kafka, DBs) runs locally via Docker—no cloud costs.
- ☁️ Cloud-Ready: Easily extend to Kubernetes, AWS, GCP, or Azure.
- 🧹 Clean Architecture: Follows SOLID, separation of concerns, and domain-driven design principles.
- 📈 Scalable: Add new microservices or swap databases with minimal changes.
- NestJS — Progressive Node.js framework
- Kafka — Distributed event streaming
- Docker — Containerization
- PostgreSQL, MongoDB, Elasticsearch — Databases
- TypeScript — Type safety
"The best architectures are those that are easy to change and scale."
- BFF Layer: Centralizes authentication, validation, and API orchestration.
- Microservices: Each service is responsible for a single domain, following separation of concerns.
- Event-Driven: Kafka decouples services, enabling async processing and resilience.
- Polyglot Databases: Each service can use the optimal database for its needs.
- Dockerized: All databases and Kafka run locally with Docker Compose for easy setup.
- Extensible: Add new services or swap technologies with minimal friction.
- Cloud-Ready: Easily migrate to cloud platforms or orchestrate with Kubernetes.
# Using HTTPS
git clone https://github.com/usman250994/Nestjs-microservices_peer_2_peer_rental_project.git
cd Nestjs-microservices_peer_2_peer_rental_projectdocker-compose up -d- This will start Kafka, Zookeeper, and Kafka UI locally. No cloud costs!
- For more, see Kafka Docker Docs.
- Each microservice (
user_management,product_management,feedback_management) has its owndocker-compose.ymlfor its database. - In each service folder, run:
docker-compose up -d- In separate terminals, run the following for each service and the BFF:
npm install
npm run start:dev- Visit http://localhost:8080 to monitor Kafka topics and messages.
- Add New Microservices: Scaffold a new NestJS service, connect it to Kafka, and add its DB via Docker.
- Cloud Deployment: Containerize services and deploy to Kubernetes, AWS ECS, GCP Cloud Run, or Azure AKS.
- Monitoring: Integrate Prometheus and Grafana for observability.
- CI/CD: Use GitHub Actions or GitLab CI for automation.
"A clean, scalable, and modern microservices boilerplate for real-world projects and portfolios."
- Fork and adapt for your own SaaS, marketplace, or event-driven platform.
Medium arcticle peer to peer rental platform