Definition
- Transcoding pipeline : asynchronous workers convert raw uploads into multiple resolutions and bitrates, producing segments and a manifest.
- Adaptive bitrate streaming (ABR) : HLS or DASH protocols let the player request segments at a bitrate matching current bandwidth.
- CDN delivery : segments are served from edge servers near viewers for low latency and reduced origin load.
- Recommendation engine : precomputes suggestions from viewing history and similarity, served from a fast store.
- Sharded counters : distribute view count increments across many shards to avoid write bottlenecks on popular videos.
National Bank of India produces training videos for customers. When a video is uploaded, the bank converts it into several quality versions, cuts each into small segments, and stores copies near customers. As Rajesh watches, the player picks the quality his internet can handle. The bank suggests related videos and keeps a rough count of views.
Understanding the Concepts
How does the upload and transcoding pipeline work?
The raw upload lands in object storage (S3-like), emitting an event that queues transcoding jobs. Workers produce a bitrate ladder (240p, 480p, 720p, 1080p) and cut each into short segments (typically 2 to 10 seconds). Each segment is independently downloadable. A manifest file lists all quality levels and their segment URLs. At National Bank of India, when the training team uploads a new compliance video, the pipeline produces all quality versions automatically.
package com.bank.video;
import java.util.List;
public class TranscodePipeline {
public void onUpload(String videoId, String rawPath) {
for (String profile : List.of("240p", "480p", "720p", "1080p"))
transcodeQueue.publish(new TranscodeJob(videoId, rawPath, profile));
}
}
How does CDN delivery work?
Transcoded segments are distributed to CDN edge servers near viewers. When Rajesh in Mumbai watches, his player fetches segments from the Mumbai edge, not the origin in Delhi. The CDN caches segments on first request and serves subsequent requests from cache. Cache hit ratio is a key metric: above 95 percent means the origin handles little traffic.
package com.bank.video;
public class CDNService {
public String getSegmentUrl(String videoId, String quality, int segmentIndex) {
String originPath = String.format("/videos/%s/%s/seg-%d.ts", videoId, quality, segmentIndex);
return cdnDomain + originPath; // CDN intercepts and caches
}
}
How does adaptive bitrate streaming work?
The player downloads a manifest listing all quality levels and their segment URLs. For each segment, the player picks the highest quality that fits the current bandwidth. If bandwidth drops mid-video, the player switches to a lower quality seamlessly. The viewer sees a brief quality change but no buffering.
package com.bank.video;
import java.util.Comparator;
import java.util.List;
public class BitrateSelector {
public String selectVariant(List<Variant> ladder, long bandwidthBps) {
return ladder.stream()
.filter(v -> v.bitrate() <= bandwidthBps)
.max(Comparator.comparingLong(Variant::bitrate))
.map(Variant::url).orElse(ladder.get(0).url());
}
}
How does the recommendation engine work?
Analyze viewing history and content similarity offline. Compute user-to-user and item-to-item similarity matrices. Store precomputed recommendations in a fast store (Redis or DynamoDB). When Rajesh finishes a video on loan basics, the system suggests related videos on EMI calculation and interest rates.
package com.bank.video;
import java.util.List;
public class RecommendationService {
public List<String> recommend(String userId, int limit) {
List<String> precomputed = recommendationStore.get(userId);
if (precomputed != null) return precomputed.subList(0, Math.min(limit, precomputed.size()));
return popularVideos(limit); // fallback for new users
}
}
How do you count views at scale?
Exact counters bottleneck on popular videos because every view hits the same database row. Sharded counters spread increments across N shards. A periodic aggregation job sums the shards into a display count. The count may lag by a few seconds, which is acceptable.
package com.bank.video;
import java.util.concurrent.ThreadLocalRandom;
public class ShardedViewCounter {
private static final int SHARD_COUNT = 100;
public void increment(String videoId) {
int shard = ThreadLocalRandom.current().nextInt(SHARD_COUNT);
counterStore.increment(videoId + ":shard:" + shard);
}
public long totalViews(String videoId) {
long total = 0;
for (int i = 0; i < SHARD_COUNT; i++)
total += counterStore.get(videoId + ":shard:" + i);
return total;
}
}
What about the control plane vs data plane?
The control plane handles authorization (who can watch what) and is strongly consistent. The data plane handles segment delivery and view counts and is eventually consistent. This separation prevents a slow authorization check from blocking video playback.
What about content moderation?
Uploaded videos go through automated review (scanning for prohibited content) and optional manual review before becoming publicly visible. The video remains in a PROCESSING state until moderation passes.
What should a senior engineer know?
A senior engineer separates the slow transcoding pipeline from the fast delivery path, monitors CDN cache hit ratios, and designs the recommendation engine to be updatable without full recomputation. They also plan for DRM (digital rights management) for premium content and design the transcoding queue to handle priority levels so urgent videos are processed first.
Visual Overview
Video Streaming Platform
Upload path (async):
┌──────────┐ raw video ┌──────────┐ event ┌──────────────┐
│ Creator │────────────►│ Object │────────►│ Transcode │
└──────────┘ │ Storage │ │ Workers │
└──────────┘ │ 240p,480p, │
│ 720p,1080p │
└──────┬───────┘
│ segments
Delivery path (fast): ▼
┌──────────┐ HLS/DASH ┌──────────┐ segments ┌──────────┐
│ Viewer │◄───────────│ CDN │◄────────────│ Origin │
│ (player) │ adaptive │ (edge) │ │ Storage │
└──────────┘ bitrate └──────────┘ └──────────┘
View counting:
View event ──► Sharded counters ──► Aggregate (eventually consistent)
Key Takeaway
A video streaming platform turns one upload into a smooth experience for millions of viewers. The transcoding pipeline is asynchronous: raw video lands in storage, workers produce a bitrate ladder and segments. CDN edge servers deliver segments near viewers. Adaptive bitrate streaming (HLS/DASH) lets the player switch quality seamlessly.
View counting uses sharded counters because exact counters bottleneck on popular videos. The control plane is strongly consistent; the data plane is eventually consistent.
Remember one sentence: transcode asynchronously into multiple bitrates, deliver segments via CDN with adaptive streaming, and use sharded counters for view counting at scale.
---