A production-grade, event-driven microservices architecture powering core social-media features such as authentication, posting, media uploads, and search. Built for scalability, modular deployment, and real-world backend engineering.
-
Overview
-
Purpose & Scope
-
Key Capabilities
-
Technology Stack
-
Architecture & Services
-
API Gateway
-
Identity Service
-
Post Service
-
Media Service
-
Search Service
-
Infrastructure Components
-
-
Project Structure
-
Getting Started
-
Configuration & Deployment
-
Security & Performance Features
-
Next Steps
-
License
This platform is a distributed, event-driven system designed to support full social media backend functionality – including user registration/login, content posting, media uploads, and search/discovery. The system is built using a true microservices architecture with independent services communicating via HTTP and message queues (RabbitMQ).
This README documents the high-level architecture, technology stack, and core services of the Social Media Microservices Platform. Detailed service-specific documentation (API endpoints, routing, models) and design decision rationales are available in the project documentation.
| Capability | Service(s) involved | Description |
|---|---|---|
| User Authentication | Identity Service | Registration, login, JWT token generation and refresh, password security. |
| User Authorization | API Gateway + Identity Service | JWT validation, role-based access control (RBAC) and rate limiting. |
| Content Management | Post Service | CRUD operations on user posts, publishing events for downstream processes. |
| Media Storage | Media Service | Handles upload of images/videos, storing to CDN (Cloudinary) + metadata. |
| Content Discovery/Search | Search Service | Maintains indices for posts/media, handles search queries. |
| Asynchronous Processing | All services via RabbitMQ | Event-driven communication across services for decoupling and scalability. |
| Rate Limiting / Caching | API Gateway, Redis | Distributed rate limiting and caching to improve responsiveness and durability. |
-
Languages / Runtime: Node.js (ES modules)
-
Core Frameworks / Libraries: Express, Mongoose, Joi, amqplib (RabbitMQ)
-
Infrastructure: Docker, Docker Compose, Redis, RabbitMQ, MongoDB, Cloudinary
-
Security & Logging: Helmet, CORS, Winston, JWT, Joi, argon2 (for password hashing).
| Service | Key packages | Role |
|---|---|---|
| API Gateway | express, express-http-proxy, express-rate-limit, rate-limit-redis, jsonwebtoken, helmet, cors, winston | Entry point, routing, JWT validation, rate limiting. |
| Identity Service | express, mongoose, argon2, jsonwebtoken, joi, validator, rate-limiter-flexible, cookie-parser | User auth/management, token generation & validation. |
| Post Service | express, mongoose, amqplib, joi, winston | CRUD posts, event publishing. |
| Media Service | express, mongoose, multer, cloudinary, amqplib, joi | Media upload, CDN integration, event handling. |
| Search Service | express, mongoose, amqplib, joi, winston | Indexing, search queries, event consumption. |
-
Acts as the single entry point for all client requests (default port: 3000)
-
Implements routing via express-http-proxy to backend services
-
JWT validation, distributed rate limiting (via express-rate-limit + Redis)
-
Security headers (Helmet), CORS handling, request logging (Winston)
-
Runs on default port 3001
-
User registration (password hashing with argon2), login, token generation/refresh
-
Input validation with Joi & Validator
-
Built-in rate-limiting per IP via rate-limiter-flexible
-
Handles creation, reading, updating, deletion of user posts
-
Uses MongoDB (via Mongoose) for data persistence and optimized schema for reads/writes
-
Publishes lifecycle events (e.g., post_created, post_deleted) to RabbitMQ for downstream services
-
Handles file uploads (images/videos) via multer
-
Stores media files in Cloudinary CDN and maintains metadata in MongoDB
-
Listens to RabbitMQ events to trigger media cleanup or indexing
-
Maintains search indices (stored in MongoDB) for fast content discovery
-
Consumes events from RabbitMQ (e.g., new post, new media) to update indices in real time
-
Exposes REST endpoints for search queries
-
Redis (redis:alpine): Used for distributed caching and rate limiting store. URL: redis://redis:6379.
-
RabbitMQ (rabbitmq:3-management): Message broker for asynchronous, inter-service communication (ports: 5672 for AMQP, 15672 for UI). URL: amqp://rabbitmq:5672.
-
MongoDB: Each service manages its own collections (Database-per-service pattern): e.g., Users, Posts, Media, SearchIndices.
-
Cloudinary: The media service uses Cloudinary for storing uploaded media files.
├── api-gateway/
│ ├── package.json
│ └── src/
│ └── server.js
├── identity-service/
│ ├── package.json
│ └── src/
│ └── server.js
├── post-service/
│ ├── package.json
│ └── src/
│ └── server.js
├── media-service/
│ ├── package.json
│ └── src/
│ └── server.js
├── search-service/
│ ├── package.json
│ └── src/
│ └── server.js
├── docker-compose.yml
└── .gitignore
Each service is self-contained: its own dependencies, .env config, version control, and deployment lifecycle. DeepWiki
- Clone the repository
git clone https://github.com/geniuscode124/Social-media-Microservices
cd social-media-microservices
- Configure .env files Each service has its own .env.example. Copy and fill them:
cp api-gateway/.env.example api-gateway/.env
cp identity-service/.env.example identity-service/.env
# same for others...
Typical variables include:
REDIS_URL=redis://redis:6379
RABBITMQ_URL=amqp://rabbitmq:5672
MONGO_URI=mongodb://mongo:27017/<service-db>
CLOUDINARY_API_KEY=...
- Start the full stack Ensure Docker and Docker Compose are installed.
docker-compose up --build
This will start all required services (api-gateway, identity-service, post-service, media-service, search-service), plus Redis, RabbitMQ, MongoDB.
-
Access the API Gateway at http://localhost:3000 to begin interacting with the API.
-
Explore individual service endpoints (see service docs) for advanced workflows.
-
Each service loads configuration from environment variables (via .env). Shared infrastructure variables include:
-
REDIS_URL=redis://redis:6379
-
RABBITMQ_URL=amqp://rabbitmq:5672
-
-
The entire stack is containerised using Docker Compose, enabling modular deployment and easy horizontal scaling.
-
Rate limiting and logging are implemented at the gateway and across services to ensure production-ready observability and resilience.
-
JWT-based Authentication + RBAC: Secure token management for user sessions and role-based permissions across services.
-
Distributed Rate Limiting: Using Redis and rate-limit libraries at the gateway to protect services from abuse or overload.
-
Event-Driven Architecture: RabbitMQ ensures asynchronous workflows, loose coupling between services, and high scalability.
-
Database per Service Pattern: Each microservice operates on its own collections/schema, reducing inter-service dependencies and enabling independent evolution.
-
Containerisation: Services are isolated, making deployments reproducible and scaling straightforward.
-
Optimised Data Access: Services use MongoDB with appropriate indexing and query optimisation to support high performance (especially search and media services).
-
Add notification service for in-app / email alerts when certain events occur (likes, comments, mentions).
-
Extend media service to support video transcoding and streaming.
-
Introduce GraphQL façade to offer alternative query flexibility to frontend clients.
-
Deploy to a cloud-native orchestration environment (Kubernetes) for production readiness at scale.
-
Add observability stack (Prometheus, Grafana) for real-time metrics and dashboards.
-
Expand search service to support faceted search and full-text ranking.
MIT