Skip to content

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.

Screenshot 2024-11-27 at 12.59.27 PM.png

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 registered
    • 400 Bad Request: Validation errors
    • 409 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=Strict in 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 created
    • 400 Bad Request: Validation errors
    • 409 Conflict: Slug already exists
    • 411 - 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 file
    • title: Video title
    • description: Video description
    • category: 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 updated
  • 400 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

  1. Video Processing
    • Use FFmpeg for transcoding
    • Asynchronous processing queue
    • Store video metadata in database
    • Use distributed storage (S3/Google Cloud Storage)
  2. Scalability
    • Horizontal scaling for video processing
  3. Security
    • Rate limiting on upload and API endpoints
    • Input validation