Skip to content

About

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.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Repository files navigation

Social Media Microservices Platform

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.


  1. Overview

  2. Purpose & Scope

  3. Key Capabilities

  4. Technology Stack

  5. Architecture & Services

    • API Gateway

    • Identity Service

    • Post Service

    • Media Service

    • Search Service

    • Infrastructure Components

  6. Project Structure

  7. Getting Started

  8. Configuration & Deployment

  9. Security & Performance Features

  10. Next Steps

  11. License

Overview

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

Purpose & Scope

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.

Key Capabilities

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.

Technology Stack

  • 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 dependencies summary

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.

Architecture & Services

API Gateway (api-gateway)

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

Identity Service (identity-service)

  • 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

Post Service (post-service)

  • 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

Media Service (media-service)

  • 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

Search Service (search-service)

  • 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

Infrastructure Components

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

Project Structure

├── 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

Getting Started

  1. Clone the repository
git clone https://github.com/geniuscode124/Social-media-Microservices
cd social-media-microservices
  1. 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=...
  1. 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.

  1. Access the API Gateway at http://localhost:3000 to begin interacting with the API.

  2. Explore individual service endpoints (see service docs) for advanced workflows.

Configuration & Deployment

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

Security & Performance Features

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

Next Steps / Future Enhancements

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

License

MIT

About

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.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages