CDN - a content delivery network is a system of geographically distributed servers used to transport media files. The purpose of the CDN is to host live streaming videos to users. CDN works like amazon warehouse. If closest edge server does have resource cached, it will deliver it to the user. If not, it will deliver the media by requesting to another network. (Think of it like globally connected highways for data).
Advantage of CDNS - scalability, speed, quality and security.
When CDNs are not needed - Small audience, limited budget.
Every year people are abandoning traditional satellite and cable services and switching to live streaming.(favoring towards netflix over broadbands).
.ts, .mp4, there are various media formats and it can be bothersome and burden towards memory to have all these different formats available for end users. So came up with the solution of cmaf, making a universal media format for all media content.
CMAF also provides low latency, by dividing original media file into small pieces called chunks.
Using a super class with multiple sub classes, and depending on input returns one sub class. Factory pattern allows no actual instantiation on client code.
Singleton pattern only allows for one instance of the class to be created and exist in JVM.
- Gof Creational Pattern
- Only one instance of class
- Must have global access point to create the instance
- Singleton pattern is used for logging, drivers objects and caching and thread pool.
Singleton pattern could be implemented in different ways but must have the following:
1. private constructor to restrict instantiation of the class from other classes.
2. private static variable of the same class that is the only instance of the class
3. public static class that returns the instance of the class.
1. Eager initialization
instance is created at the time of class loading, easiest to code but has many drawbacks.
- instance is created regardless w/o considering the possibility of not using the class.
- doesnt provide any exception handling
2. Static block intialization
similar to eager initialization, but adds static when creating instance for exception handling. Eager intialization and Static block intialization instances are created when class is being loaded so it is not the best method to create a singleton pattern.
3. Lazy Initialization
Creates instance inside the global access method. It works fine in single-threaded environment but when working with multiple threads, if both threads are created at the same time, the singleton pattern will not working causing it to create two different instances of the class.
4. Thread Safe Singleton
applying synchronized to a global access method will allow thread wait for other working threads when using the method. But applying synchronized directly to the method will cause unnecessary time costs so for this, we can add a synchronized block inside another if statement, a double checked locking principle.
5. Bill Pugh Singleton Implementation
Bill Pugh created a pattern where using inner static helper class to create a thread safe singleton instance.
SingletonHelper class is not loaded into the memory until getInstance is called, which saves unnecessary memory costs. This is most widely used singleton pattern.