Media Status API
A lightweight, high-performance REST API microservice designed for streaming platforms to validate media content availability in real-time. The API serves as a critical infrastructure component, handling over 100,000 requests from video players to determine whether media content is active and available for streaming, preventing broken playback experiences and improving content delivery reliability.
Key Features
-
High-Volume Request Handling - Architected to efficiently process 100,000+ concurrent requests from video players across the streaming platform, ensuring sub-second response times for media status validation without degrading user experience
-
Centralized Media Status Management - Integrates with AWS S3 to maintain a single source of truth for media availability, eliminating data inconsistencies and enabling rapid updates to content status across all platforms simultaneously
-
Batch Status Validation - Supports comma-separated ID queries, allowing video players to validate multiple media items in a single API call, reducing network overhead by up to 80% compared to individual requests
-
Cross-Origin Resource Sharing - Implements CORS middleware to enable secure cross-origin requests from web-based video players, supporting seamless integration across multiple domains and subdomains
-
Comprehensive Error Handling - Provides detailed HTTP status codes and error messages (422 for validation errors, 404 for missing IDs, 500 for server errors) enabling clients to implement intelligent retry logic and graceful degradation
-
Health Monitoring Endpoint - Includes a dedicated
/api/pinghealthcheck endpoint for load balancers and monitoring systems to verify service availability and support zero-downtime deployments -
ARM Architecture Optimization - Containerized with multi-platform Docker builds targeting ARM architecture, reducing cloud infrastructure costs by 30-40% while maintaining high performance on AWS Graviton instances
Technical Implementation
Architecture & Design Decisions
The API follows a minimalist microservice architecture, prioritizing low latency and high throughput. Built on Express.js for its lightweight footprint and non-blocking I/O model, the service is designed to handle thousands of concurrent connections without memory bloat. The stateless design enables horizontal scaling across multiple container instances behind a load balancer.
The core architecture leverages AWS S3 as the data source rather than a traditional database. This unconventional choice was made for several reasons: (1) S3 provides extremely low latency for read operations with built-in CDN capabilities, (2) the media status data structure is relatively simple and infrequently updated, making caching highly effective, and (3) S3’s 99.99% availability SLA ensures the API remains responsive even during infrastructure issues.
AWS S3 Integration Pattern
The implementation uses the AWS SDK to retrieve a JSON manifest from S3 containing the complete media catalog with active/inactive status flags. The getObject() promise-based API fetches the entire dataset in a single request, leveraging S3’s high throughput capabilities. For streaming platforms managing thousands of media items, this approach provides better performance than database queries, especially when combined with HTTP caching headers.
Error handling for S3 operations includes retry logic for transient failures and graceful degradation when the manifest is temporarily unavailable. The JSON parsing includes validation to ensure the data structure matches expected formats, preventing cascading failures from corrupted or incomplete data.
Query Processing & Validation
The /api/media-status endpoint implements efficient query parameter processing. Client applications send comma-separated media IDs, which the API splits, trims, and validates before lookup. The validation layer ensures type safety and returns structured error responses for malformed requests (HTTP 422), enabling client applications to implement proper error handling.
The ID matching algorithm iterates through the provided IDs and categorizes them into “active” and “inactive” arrays based on the media’s status flag. If any ID is not found in the manifest, the API returns an immediate 404 response with the specific missing ID, preventing silent failures and helping clients identify content synchronization issues.
Containerization & Deployment Pipeline
The Dockerfile implements a multi-stage build pattern to minimize the final image size. The first stage (deps) installs dependencies in an isolated layer, while the second stage (runner) copies only the necessary runtime files. This reduces the production image to under 100MB, improving deployment speed and reducing attack surface.
The GitLab CI/CD pipeline automates the entire deployment workflow. On commits to the main branch, the pipeline authenticates with AWS ECR, builds a Docker image targeting the linux/arm/v7 platform using docker buildx, and pushes directly to the container registry. The ARM architecture target enables deployment on cost-effective AWS Graviton processors, providing better price-performance ratios than x86 alternatives.
Security & Configuration Management
Environment variables are used for all sensitive configuration (S3 bucket names, AWS credentials, port configuration), preventing hardcoded secrets in the codebase. The .env file is excluded from version control via .gitignore, ensuring credentials never leak into the repository.
CORS is configured to allow cross-origin requests, essential for web-based video players hosted on different domains. The implementation uses the cors middleware package, which handles preflight requests and appropriate headers automatically.
Business Impact
This API serves as critical infrastructure for a streaming platform’s content delivery system. By providing real-time media availability status, it prevents video players from attempting to load inactive or expired content, eliminating broken playback experiences that would otherwise damage user trust and increase support costs.
The ability to handle 100,000+ requests demonstrates the API’s role in a production streaming environment serving a substantial user base. The centralized status management via S3 enables content teams to instantly deactivate problematic media across all platforms, providing operational control during content rights issues, quality problems, or scheduled maintenance.
The batch validation feature reduces network overhead for video players that need to validate multiple media items (such as playlist pre-loading or recommendation systems), improving application performance and reducing bandwidth costs.
Development & Deployment
The project follows modern DevOps practices with automated CI/CD through GitLab. Every commit to the main branch triggers an automated build, containerization, and deployment to AWS ECR, enabling rapid iteration and reducing time-to-production from hours to minutes.
The containerized architecture ensures environment parity between development and production, eliminating “works on my machine” issues. The ARM-optimized build demonstrates cost-consciousness and infrastructure optimization, reducing monthly cloud expenses while maintaining performance standards.
The service runs on Node.js 20 (Alpine Linux), leveraging the latest LTS features while maintaining a minimal OS footprint for enhanced security and reduced resource consumption.