It depends on how much of this you implement and whether you use existing libraries, but the core functionality isn’t overly complex. Here’s a breakdown of effort by component:
- Disk-Based Caching (Medium Complexity)
What’s needed?A way to store and retrieve segments on disk.A background cleanup job to remove old files.A simple file-locking mechanism to avoid duplicate downloads.
A way to store and retrieve segments on disk.
A background cleanup job to remove old files.
A simple file-locking mechanism to avoid duplicate downloads.
Implementation:You can use Go’sospackage for file operations andgithub.com/gofrs/flockfor file-based locking.A simple cleanup job can run periodically withtime.Ticker.
You can use Go’sospackage for file operations andgithub.com/gofrs/flockfor file-based locking.
A simple cleanup job can run periodically withtime.Ticker.
Difficulty:Medium(Basic file I/O and cleanup logic).
What’s needed?
A way to store and retrieve segments on disk.
A background cleanup job to remove old files.
A simple file-locking mechanism to avoid duplicate downloads.
A way to store and retrieve segments on disk.
A background cleanup job to remove old files.
A simple file-locking mechanism to avoid duplicate downloads.
Implementation:
You can use Go’sospackage for file operations andgithub.com/gofrs/flockfor file-based locking.
A simple cleanup job can run periodically withtime.Ticker.
You can use Go’sospackage for file operations andgithub.com/gofrs/flockfor file-based locking.
A simple cleanup job can run periodically withtime.Ticker.
Difficulty:Medium(Basic file I/O and cleanup logic).
- ISM-to-DASH Conversion Caching (Low to Medium Complexity)
What’s needed?Fetch the ISM manifest once per channel.Convert it into a DASH manifest and save it for reuse.Serve the pre-generated DASH manifest to users.
Fetch the ISM manifest once per channel.
Convert it into a DASH manifest and save it for reuse.
Serve the pre-generated DASH manifest to users.
Implementation:Store the DASH manifest and init segment in memory or disk.Use a simplesync.Mapor a lightweight file cache for this.
Store the DASH manifest and init segment in memory or disk.
Use a simplesync.Mapor a lightweight file cache for this.
Difficulty:Low to Medium(Mostly structuring data and writing to disk).
What’s needed?
Fetch the ISM manifest once per channel.
Convert it into a DASH manifest and save it for reuse.
Serve the pre-generated DASH manifest to users.
Fetch the ISM manifest once per channel.
Convert it into a DASH manifest and save it for reuse.
Serve the pre-generated DASH manifest to users.
Implementation:
Store the DASH manifest and init segment in memory or disk.
Use a simplesync.Mapor a lightweight file cache for this.
Store the DASH manifest and init segment in memory or disk.
Use a simplesync.Mapor a lightweight file cache for this.
Difficulty:Low to Medium(Mostly structuring data and writing to disk).
- Preventing Duplicate Requests (Low Complexity)
What’s needed?Ensure that two users don’t request the same segment at the same time.
Ensure that two users don’t request the same segment at the same time.
Implementation:Use Go’sgolang.org/x/sync/singleflightto deduplicate segment downloads.
Use Go’sgolang.org/x/sync/singleflightto deduplicate segment downloads.
Difficulty:Low(It’s a built-in Go pattern, easy to implement).
What’s needed?
Ensure that two users don’t request the same segment at the same time.
Ensure that two users don’t request the same segment at the same time.
Implementation:
Use Go’sgolang.org/x/sync/singleflightto deduplicate segment downloads.
Use Go’sgolang.org/x/sync/singleflightto deduplicate segment downloads.
Difficulty:Low(It’s a built-in Go pattern, easy to implement).
- Session Management (Medium Complexity)
What’s needed?Keep track of who is watching which channel.Avoid evicting segments too quickly if users are still watching.
Keep track of who is watching which channel.
Avoid evicting segments too quickly if users are still watching.
Implementation:Store session info in memory single instance) or Redis (for distributed sessions).Update last-seen timestamps on each segment request.
Store session info in memory single instance) or Redis (for distributed sessions).
Update last-seen timestamps on each segment request.
Difficulty:Medium(Mostly state management).
What’s needed?
Keep track of who is watching which channel.
Avoid evicting segments too quickly if users are still watching.
Keep track of who is watching which channel.
Avoid evicting segments too quickly if users are still watching.
Implementation:
Store session info in memory single instance) or Redis (for distributed sessions).
Update last-seen timestamps on each segment request.
Store session info in memory single instance) or Redis (for distributed sessions).
Update last-seen timestamps on each segment request.
Difficulty:Medium(Mostly state management).
- Serving Segments Efficiently (Low Complexity)
What’s needed?Proxy requests from clients without re-downloading.
Proxy requests from clients without re-downloading.
Implementation:A simple HTTP handler that checks disk first, then fetches segments if needed.
A simple HTTP handler that checks disk first, then fetches segments if needed.
Difficulty:Low(Go’s HTTP server makes this easy).
What’s needed?
Proxy requests from clients without re-downloading.
Proxy requests from clients without re-downloading.
Implementation:
A simple HTTP handler that checks disk first, then fetches segments if needed.
A simple HTTP handler that checks disk first, then fetches segments if needed.
Difficulty:Low(Go’s HTTP server makes this easy).
Overall Difficulty
If you implement everything at once:Medium to High(several moving parts).
If you start simple (disk cache + singleflight):Low to Medium(manageable and works well).
If you implement everything at once:Medium to High(several moving parts).
If you start simple (disk cache + singleflight):Low to Medium(manageable and works well).
Would you prefer a minimal implementation first and then build on it? You can start with:
Disk cache + singleflightto avoid duplicate requests.
ISM-to-DASH conversion cacheto avoid regenerating.
Add session tracking later if needed.
Disk cache + singleflightto avoid duplicate requests.
ISM-to-DASH conversion cacheto avoid regenerating.
Add session tracking later if needed.
Would this approach work for you?