Skip to content

Repository files navigation

Social Media Microservices

A scalable social media backend built using a microservices architecture with Node.js. The system separates authentication, post management, media handling, and search into independent services communicating through REST APIs and asynchronous events.

Architecture

                        Client
                           |
                           v
                     API Gateway
                           |
          +----------------+----------------+
          |                |                |
          v                v                v
   Identity Service   Post Service     Media Service
                           |
                           v
                     RabbitMQ Events
                           |
                           v
                     Search Service

                     Redis / MongoDB

Microservices

API Gateway

The API Gateway acts as the main entry point for clients and routes requests to the appropriate microservice.

Responsibilities:

  • Request routing
  • Authentication middleware
  • Rate limiting
  • Service communication

Identity Service

Handles user authentication and identity management.

Responsibilities:

  • User registration
  • User login
  • JWT authentication
  • User validation

Post Service

Manages social media posts.

Responsibilities:

  • Create posts
  • Retrieve posts
  • Delete posts
  • Publish post events
  • Communicate with Media Service

Media Service

Handles media associated with posts.

Responsibilities:

  • Media upload
  • Media storage management
  • Media deletion
  • Media metadata management

Search Service

Provides post search functionality.

Responsibilities:

  • Index post data
  • Search posts
  • Consume RabbitMQ events
  • Maintain searchable post information

Event-Driven Communication

The application uses RabbitMQ for asynchronous communication between services.

Example event flow:

User creates a post
        |
        v
Post Service
        |
        v
Post Created Event
        |
        v
RabbitMQ
        |
        v
Search Service
        |
        v
Post indexed for search

This architecture reduces tight coupling between services and allows services to process events independently.

Tech Stack

  • Node.js
  • Express.js
  • MongoDB
  • Redis
  • RabbitMQ
  • Docker
  • Docker Compose
  • JWT Authentication
  • REST APIs

Project Structure

Social-media-Microservices/
│
├── api-gateway/
├── Identity-service/
├── Post-service/
├── media-service/
├── search-service/
│
├── docker-compose.yaml
└── .gitignore

Getting Started

Prerequisites

Make sure the following tools are installed:

  • Docker
  • Docker Compose
  • Git

Clone the Repository

git clone https://github.com/ayushman1210/Social-media-Microservices.git
cd Social-media-Microservices

Run the Application

Build and start all microservices:

docker compose up --build

Run the services in the background:

docker compose up --build -d

Stop the Application

docker compose down

Docker Services

Docker Compose manages the application services and supporting infrastructure.

api-gateway
identity-service
post-service
media-service
search-service
redis
rabbitmq

Each microservice runs independently inside its own Docker container.

Key Features

  • Microservices-based backend architecture
  • API Gateway pattern
  • JWT-based authentication
  • Event-driven communication
  • Asynchronous message processing using RabbitMQ
  • Redis integration
  • Independent service containers
  • Docker Compose orchestration
  • Post and media management
  • Event-driven search indexing

Architecture Concepts Demonstrated

This project demonstrates several backend and distributed system concepts:

  • Microservices Architecture
  • API Gateway Pattern
  • Event-Driven Architecture
  • Message Queues
  • Service Isolation
  • Asynchronous Communication
  • Distributed System Design
  • Containerization

Future Improvements

  • Kubernetes deployment
  • Distributed tracing
  • Centralized logging
  • Prometheus and Grafana monitoring
  • Automated CI/CD pipeline
  • API documentation using Swagger/OpenAPI
  • Integration and unit testing
  • Service health checks
  • Circuit breaker pattern

Author

Ayushman Gupta

GitHub: ayushman1210

About

Microservices Built in Nodejs

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages