A scalable microservices-based social media application backend built with Node.js, featuring user authentication, post management, media handling, and search capabilities.
This application follows a microservices architecture pattern with the following services:
┌─────────────────┐
│ API Gateway │
│ (Port 3000) │
└─────────────────┘
│
┌────────────────────┼────────────────────┐
│ │ │
┌──────────────┐ ┌─────────────┐ ┌──────────────┐
│ User Service │ │Post Service │ │Media Service │
│ (Port 3001) │ │ (Port 3002) │ │ (Port 3003) │
└──────────────┘ └─────────────┘ └──────────────┘
│ │ │
│ ┌───────┴───────┐ │
│ │ │ │
│ ▼ ▼ ▼
│ ┌──────────────┐ ┌─────────────┐ ┌──────────────┐
│ │Search Service│ │ RabbitMQ │ │ Cloudinary │
│ │ (Port 3004) │ │Message Queue│ │Media Storage │
│ └──────────────┘ └─────────────┘ └──────────────┘
│ │ ▲
│ │ │
▼ ▼ │
┌───────────────┐ ┌─────────┐ │
│ MongoDB │ │ Redis │──────┘
│ (Database) │ │ (Cache) │
│ │ │ │
│ • User Data │ │ • Posts │
│ • Posts │ │ • Search│
│ • Media Meta │ │ • Cache │
│ • Search Data │ └─────────┘
└───────────────┘
Data Flow:
- MongoDB: Used by all services for persistent data storage
- Redis: Used by Post Service (caching feeds) and Search Service (caching search results)
- RabbitMQ: Message queue between Post, Media, and Search services for async processing
- Cloudinary: External service for media storage and transformations
- Port:
3000 - Entry point for all client requests
- Request routing and load balancing
- Rate limiting and request validation
- Authentication middleware
- Port:
3001 - User registration and authentication
- JWT token generation and validation
- Password encryption and security
- Port:
3002 - CRUD operations for posts
- Port:
3003 - File upload and storage via Cloudinary
- Image/video processing and optimization
- Media metadata management
- Automatic image transformations and CDN delivery
- Port:
3004 - Full-text search for posts and users
- Runtime: Node.js
- Database: MongoDB
- Cache: Redis
- Message Queue: RabbitMQ
- Containerization: Docker & Docker Compose
- Authentication: JWT (JSON Web Tokens)
- Media Storage: Cloudinary
Before running this application, make sure you have the following installed:
- Node.js (v18 or higher)
- Docker and Docker Compose
- MongoDB (if running locally)
- Redis (if running locally)
- RabbitMQ (if running locally)
-
Clone the repository
git clone https://github.com/ritik6559/Node-microservices.git cd Node-microservices -
Environment Setup
# Edit .env file with your configuration -
Start all services
docker-compose up -d
-
Verify services are running
docker-compose ps
The API Gateway will be available at http://localhost:3000
-
Install dependencies for each service
# API Gateway cd api-gateway && npm install && cd .. # User Service cd user-service && npm install && cd .. # Post Service cd post-service && npm install && cd .. # Media Service cd media-service && npm install && cd .. # Search Service cd search-service && npm install && cd ..
-
Start infrastructure services
# Start MongoDB, Redis, and RabbitMQ docker-compose up -d mongodb redis rabbitmq -
Start microservices
# Terminal 1 cd api-gateway && npm start # Terminal 2 cd user-service && npm start # Terminal 3 cd post-service && npm start # Terminal 4 cd media-service && npm start # Terminal 5 cd search-service && npm start
Create a .env file in each service directory:
# API-GATEWAY .env
PORT=3000
NODE_ENV=development
USER_SERVICE_URL=http://localhost:3001
POST_SERVICE_URL=http://localhost:3002
MEDIA_SERVICE_URL=http://localhost:3003
SEARCH_SERVICE_URL=http://localhost:3004
REDIS_URL=redis://localhost:6379
JWT_SECRET=
# CLOUDINARY
CLOUDINARY_API_KEY=
CLOUDINARY_API_SECRET=
CLOUDINARY_CLOUD_NAME=
# REST
PORT=3003
MONGODB_URI=
NODE_ENV=development
REDIS_URL=redis://localhost:6379
RABBITMQ_URL=amqp://localhost:5672
# Redis
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_PASSWORD=- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Ritik Joshi