Scaler
Responsibilities(or Roles) are different from Actions. Several actions can be performed to fulfil a responsibility(or role). The class should have one responsibility(SRP) but its functionality that fulfils that responsibility should be open to extend(OCP)
SOLID
- Single Responsibility- A class should have a single responsibility
- Open-Closed - This principle aims to extend a Class’s behaviour without changing the existing behaviour of that Class.
- Liskov Substitution - If S is a subtype of T, then objects of type T in a program may be replaced with objects of type S without altering any of the desirable properties of that program.
- I — Interface Segregation
- D — Dependency Inversion - High-level modules should not depend on low-level modules. Both should depend on the abstraction. Abstractions should not depend on details. Details should depend on abstractions.
HLD
- Netflix consume 15% of world internet traffic
- Sort list of strings which is of size Peta Bytes of data
- 50*1000 (TB)*1000 (GB)*1000 (MB)*1000 (KB)*1000 Bytes
- The fancy/largest harddist is 20TB
- HLD is study of large scale systems from 50 feet high
- https://www.amazon.com/Designing-Data-Intensive-Applications-Reliable-Maintainable-ebook-dp-B06XPJML5D/dp/B06XPJML5D/ref=mt_other?_encoding=UTF8&me=&qid=
- Del.icio.us
- social bookmarking web service for storing, sharing, and discovering web bookmarks
- DNS Server - Maintains global mapping between domain and ip-address maintained by ICANN(non profit org)
- isp -jio
- google dns - 8.8.8.8 8.8.4.4
- Load balancing techniques
- round robin -> non-deterministic
- userid%N -> lot of shuffling when server goes down
- Consistent Hashing
- Put users and servers on same line/circle
- Move in one direction
- go Crazy -> use many hash function for each server
- Maintain user - server relation in load balancer
- This requires (userid+serverid) * #users -> 4bytes + 4 bytes per account
- for 1billion -> it will be 8GB ram
- Time to read 1 byte from RAM -> 100 nano secs = 0.1micro secs
- Time to read 1 byte from Magnetic disk or hard disk(disk seek) -> 10milli sec
- Difference is 100000 times
- SSD are 10 to 100 times faster than HD
- Cache is faster than RAM(L1 cache, L2 cache, L3 cache & RAM)
- Hence, neither maintaining in RAM nor HD storage is not maintainable in long run. Formula based approach is better.
- Identify formula based approach that doesn't cause shuffling
- UserId and ServerId on same number line(apply same hash function on both of them)
- f(input)-> output -> Space of values that input can have is Domain, and space of values that output can take is Range.
- Hashfunction
- irreversable
- Output should be bounded/finite
- Only users mapped to a server that goes down are impacted
- However, all the users mapped to server that went down will be moved to next sever and increase load on it.
- To avoid, other server to overload -> go crazy -> Have multiple hash for Sever alone
- Cost of hash fn -> O(1)
- Cost of consistent hash -> O(log N) -> O(log (#servers * #hashfns))
- ngnix server
- loadbalancer + reverse proxy
- Proxy
- Act on behalf of someone else -> user request goes to proxy and proxy actually talks to server.
- This is the case where multiple users talk to proxy -> proxy talks to server and returns results
- reverse proxy ->
- Redirect request to appropriate service
- This is the case when application has multiple api servers
- One user requests-> server -> one of bunch of services
LLD
- Closer look at the appln
- Individual lines of code
- Programming paradigms
VS Code
- Support from MS, GitHub, Open source, github-copilot
Inheritance vs Composition
Comments
Post a Comment