A scalable video-sharing platform built on the MERN stack.
- MongoDB
- Express
- React
- Node.js
- JWT
- Cloudinary
- Multer
Problem
Video platforms need fast uploads, reliable streaming, and an auth model that scales — without a heavy infrastructure budget.
Approach
A MERN architecture with JWT authentication, MongoDB aggregation pipelines for feeds and analytics, and Multer + Cloudinary for resilient upload and delivery. The React frontend uses the Context API for predictable state.
Architecture
- JWT access/refresh auth with middleware guards
- MongoDB aggregation pipelines for feeds & watch history
- Multer streaming upload → Cloudinary transform & CDN delivery
- React + Context API state, code-split routes
Results
- Smooth upload-to-watch flow with transformed, CDN-delivered media
- Aggregation-driven feeds that stay fast as data grows
Auth
JWT
Media
Cloudinary
Stack
MERN
// code
vtube.ts
// Aggregation: a creator's feed with view counts
const feed = await Video.aggregate([
{ $match: { owner: userId, published: true } },
{ $lookup: {
from: "likes", localField: "_id",
foreignField: "video", as: "likes",
} },
{ $addFields: { likeCount: { $size: "$likes" } } },
{ $sort: { createdAt: -1 } },
{ $limit: 20 },
]);lessons learned
- Aggregation pipelines beat N+1 queries for feeds — shape the data in the DB.
- Stream uploads to Cloudinary; never buffer large media in app memory.
- Refresh-token rotation is worth the extra complexity for long sessions.