Real time Youtube like application
Real time YouTube-Like Application API Specification
You’re supposed to create a Youtube like application where everyone who is watching a specific video is synced with each other and looking at the same timestamp. If one user changes the timestamp (by hitting the PUT /api/videos/{video_id}/time endpoint), every user who is currently subscribed to that room should receive this update.

Authentication Endpoints
User Registration
- Endpoint:
POST /api/auth/signup - Request Body:
{ "email": "user@example.com", "password": "securePassword123", "username": "unique_username"}- Response:
201 Created: User successfully registered400 Bad Request: Validation errors409 Conflict: Username or email already exists
User Login
- Endpoint:
POST /api/auth/login - Request Body:
{ "email": "user@example.com", "password": "securePassword123"}- Response:
200 OK:
{ "access_token": "jwt_token_here", "user": { "id": "user_uuid", "username": "unique_username", "email": "user@example.com" }}- Set-Cookie:
Authentication=jwt_token_here; HttpOnly; Secure; SameSite=Strictin the header
Video Feed Endpoints
Get Video Feed (unauthenticated)
- Endpoint:
GET /api/videos/feed - Query Parameters:
page: Current page number (default: 1)limit: Number of videos per page (default: 20)category: Optional video category filter
- Response:
{ "videos": [ { "id": "video_uuid", "title": "Video Title", "thumbnail_url": "<https://example.com/thumbnail.jpg>", "creator": { "id": "creator_uuid", "username": "creator_username" }, "view_count": 1000, "created_at": "2024-01-01T00:00:00Z" } ], "total_pages": 5, "current_page": 1}Channel Endpoints
Create Channel (Authenticated)
A single user should be able to create only one channel
- Endpoint:
POST /api/channels - Request Body:
{ "name": "My Awesome Channel", "description": "Channel description", "slug": "unique_channel_slug"}- Response:
201 Created: Channel successfully created400 Bad Request: Validation errors409 Conflict: Slug already exists411- User already has a channel
Get Channel Details (Authenticated)
- Endpoint:
GET /api/channels/{slug} - Response:
{ "id": "channel_uuid", "name": "My Awesome Channel", "description": "Channel description", "subscriber_count": 1000, "videos": [ { "id": "video_uuid", "title": "Video Title", "thumbnail_url": "<https://example.com/thumbnail.jpg>" } ]}Video Upload Endpoints
Upload Video (Authenticated)
- Endpoint:
POST /api/videos/upload - Request: Multipart form-data
file: Video filetitle: Video titledescription: Video descriptioncategory: Video category
- Response:
{ "id": "video_uuid", "title": "Uploaded Video", "processing_status": "PROCESSING", "qualities": ["240p", "480p", "720p"]}Get Video Details
This endpoint may or may not return the video details based on if the video has been transcoded or not.
- Endpoint:
GET /api/videos/{video_id} - Response:
{ "id": "video_uuid", "title": "Video Title", "description": "Video description", "creator": { "id": "creator_uuid", "username": "creator_username" }, "status": "PROCESSING"}Or
{ "id": "video_uuid", "title": "Video Title", "description": "Video description", "creator": { "id": "creator_uuid", "username": "creator_username" }, "video_urls": { "240p": "<https://example.com/video_240p.mp4>", "480p": "<https://example.com/video_480p.mp4>", "720p": "<https://example.com/video_720p.mp4>" }, "current_timestamp": 45.5, "view_count": 1000, "status": "TRANSCODED"}Update Timestamp (authenticated)
- Endpoint:
PUT /api/videos/{video_id}/time - Payload:
{ "video_id": "video_uuid", "timestamp": 45.5}Response
201 Created: Timestamp updated400 Bad Request: Validation errors/Time incorrect (longer than video / negative)
WebSocket Specification
Subscribe to Video (Client to server)
- Outgoing Event:
video:subscribe - Payload:
{ "type": "video:subscribe", "video_id": "video_uuid"}UnSubscribe to Video (Client to server)
- Outgoing Event:
video:unsubscribe - Payload:
{ "type": "video:unsubscribe", "video_id": "video_uuid"}Timestamp Broadcast (Server to client)
- Outgoing Event:
video:timestamp_updated - Payload:
{ "type": "video:timestamp_updated", "timestamp": 45.5, "user_id": "user_uuid"}Authentication
User needs to send the jwt in either the Authorization header. They should receive a 403 status code if they dont. It should be formatted as Bearer jwt
Authorization: "Bearer jwt_token"Additional Technical Considerations
- Video Processing
- Use FFmpeg for transcoding
- Asynchronous processing queue
- Store video metadata in database
- Use distributed storage (S3/Google Cloud Storage)
- Scalability
- Horizontal scaling for video processing
- Security
- Rate limiting on upload and API endpoints
- Input validation