Back to projects
System Design & Architecture
Deep Dive Engineering Case Study

Multi-Tenant LMS - Enterprise Educational Platform

Zero-Egress HLS Streaming & Microservice LMS Architecture

Bandwidth Egress:$0 (Zero Egress)
Architecture:Microservices + R2
Tenancy:Multi-Tenant RBAC
Next.jsTypeScriptNode.jsExpress.jsMongoDBCloudflare R2FFmpegHLSWebSocketsSocket.IOGoogle OAuthJWTDocker

System Design & Network Topology

Multi-Tenant LMS - Enterprise Educational Platform Architecture Diagram
Click to enlarge diagram
Eraser Architecture Spec
2-Minute Architecture Summary

“This LMS is an enterprise multi-tenant platform I built end-to-end to streamline academic workflows - from hierarchical onboarding to zero-egress HLS video delivery and live doubt clearing. Using Next.js, Node.js, MongoDB, and Cloudflare R2, I eliminated recurring video bandwidth costs and prevented server memory crashes through isolated microservice architecture.”

Problem Statement & Business Need

Educational institutes face high operational overhead and prohibitive SaaS costs when managing multi-role onboarding, video delivery, and student assessment. This LMS provides a unified, low-cost multi-tenant platform with role-based access control, zero-egress video streaming, and real-time classroom interaction.

High-Level Architecture & Flow

Next.js + TypeScript frontend serves as both the responsive client interface and a secure API reverse proxy. The backend is a microservice cluster in Node.js/Express composed of a Main API Service, a real-time WebSocket Doubt Service, and an asynchronous FFmpeg Stream Transcoding Service. Media assets are uploaded directly to Cloudflare R2 via pre-signed URLs and distributed via Cloudflare CDN with zero egress costs.

Core Engineering Responsibilities & Contributions

Database Design

Designed a hierarchical multi-tenant MongoDB schema with strict ObjectId referencing and middleware-enforced tenant boundaries between Superadmins, Institutes, Faculty, Students, and Courses.

Streaming Infrastructure

Implemented a custom zero-egress HLS video pipeline with FFmpeg transcoding, chunking videos into .m3u8 playlists stored in Cloudflare R2.

Network & Security Proxy

Configured Next.js rewrites to proxy backend microservices through a unified origin, resolving CORS and browser mixed-content restrictions.

Authentication Matrix

Engineered Google OAuth with state-based redirect parameters to securely assign multi-tenant roles on the fly and generate signed JWTs.

APIs & Real-Time Engine

Built REST endpoints for anti-cheat quiz evaluations and real-time Socket.IO channels for institute doubt resolution.

Key Architectural Decisions & Trade-Offs (Why X over Y)

Why MongoDB instead of PostgreSQL?

Educational content (courses, modules, chapters, varied quiz types) is deeply nested and dynamic. MongoDB document storage prevents expensive multi-table SQL joins while maintaining rapid query flexibility.

Why Cloudflare R2 instead of AWS S3?

Traditional cloud providers levy steep video egress fees. R2 coupled with Cloudflare CDN eliminates bandwidth egress charges completely, cutting media delivery costs by nearly 100%.

Why decouple Stream Service into a separate microservice?

FFmpeg video transcoding is heavily CPU and memory intensive. Isolating it prevents transcoding jobs from starving the event loop of the primary transactional REST API.

Production Challenges & How They Were Solved

BOTTLENECK

Server Out-of-Memory (OOM) Crashes during Transcoding

Resolution:

Concurrent 1080p transcoding was exhausting RAM on small compute instances. Decoupled transcoding into an independent worker, provisioned 8GB swap memory, and constrained FFmpeg thread concurrency.

BOTTLENECK

Browser Mixed-Content and CORS Blocking

Resolution:

Deploying microservices across multiple ports created browser origin friction. Leveraged Next.js rewrite proxies to route all client requests through a single unified domain.

Scalability & 100k Concurrent Users Roadmap

  • 01.Scale to 100k users by introducing Redis caching for hot course metadata and deploying MongoDB read replicas for query distribution.
  • 02.Adopt RabbitMQ or Apache Kafka message queues for reliable asynchronous video ingestion pipelines.
  • 03.Deploy microservice containers to AWS EKS with Horizontal Pod Autoscaling (HPA).

Key System Highlights

  • Multi-tenant MongoDB schema with strict tenant isolation and role matrices
  • Zero-Egress custom HLS streaming pipeline via FFmpeg, Cloudflare R2, and Cloudflare CDN
  • Next.js reverse proxy routing microservices to bypass CORS and mixed-content issues
  • Google OAuth onboarding with dynamic state-based multi-tenant role assignment
  • Decoupled Stream Service with 8GB swap memory and thread limits preventing OOM crashes
  • Real-time WebSocket doubt resolution and anti-cheating quiz grading engine