EZF-002 Webhooks API Architecture Style, Load Balancing Methods, HTTP Status Codes, Fundamental Latency Metrics to Remember, Git commands Part 1 (21 commands)
Recap on system design for this week:
Webhooks API Architecture style
Load Balancing Methods. Part 1 (7 Methods)
HTTP Status Codes
Fundamental Latency Metrics to Remember
Git commands. Part 1 (21 commands)
1. Webhooks API Architecture style
1.1. Message formats:
JSON
1.2. โ
Advantages:
Real-Time Notifications ๐จ: Immediate alerts without polling.
Event-Driven โก: Supports dynamic, event-based interactions.
Reduced Server Load ๐: Sends data only on events.
Configurable ๐ง: Tailored to specific events.
Simple to Use ๐ข: Generally straightforward implementation.
Asynchronous Operations ๐: Non-blocking data transfers.
Scalable ๐: Adapts easily with growing needs.
1.3. โ Disadvantages
Security Concerns ๐: Public endpoints may pose risks if not secured.
Error Handling โ: Challenges with endpoint failures or errors.
Latency Issues ๐ข: Network delays can affect real-time nature.
Resource Use ๐: Each call consumes server resources.
Debugging ๐: Complexity increases with third-party services.
Limited Filtering ๐ซ: Some providers may lack detailed options.
Ordering ๐ฆ: No guaranteed sequence for events.
1.4. ๐ Use cases
Real-Time Notifications ๐จ: Immediate alerts for events like new posts.
CI/CD ๐ : Trigger builds, tests, and deployments on code changes.
E-Commerce Updates ๐: Notify on order placements, payments, or stock changes.
CMS ๐: Alerts on content changes.
Social Media Integration ๐ฒ: Updates on posts and interactions.
Monitoring & Analytics ๐: Alerts for system or security issues.
Chatbots ๐ฌ: Notifications for new messages.
Payments ๐ณ: Status updates on transactions.
IoT Device Communication ๐: Send data when specific conditions are met by IoT devices.
Collaboration Tools Integration ๐ค: Notify on task updates or new messages in collaboration apps.
โ What API architecture style are you guys currently utilizing in your system?
2. Load Balancing Methods: Round Robin, Sticky Round Robin, Weighted Round Robin, IP Hash, Generic Hash, Least Connections, Least Time
More detailed:
2.1.ย ๐Round Robin
Distributes requests sequentially across all servers in the pool. Simple and predictable.
Static
Pros:
Easy Setup ๐ข: Minimal configuration
Even Distribution ๐: Suitable for testing.
No Monitoring Needed ๐: Rotates through servers.
Predictable ๐: Can anticipate server handling.
Cons:
Server Overload Risk โ ๏ธ: Can push servers to overload if they're already heavily loaded.
Requires Similar Server Capacity ๐: Best when all servers have roughly the same capacity.
Content Uniformity Needed ๐: Requires all servers to host the same content.
Use Cases:
Testing Environments ๐งช: Balanced request distribution for testing.
Stateless Applications ๐: For independent, session-less requests.
Uniform Server Capacities ๐: When all servers have similar resources.
Microservices ๐: Even distribution across stateless services.
Example (NGINX):
upstream backend {ย ย server s1.dmn.com;ย ย serverย s2.dmn.com;ย ย serverย s3.dmn.com;}
2.2. ๐ข๐ย ย Sticky Round Robin
Distributes requests sequentially but ensures a user's subsequent requests stick to the initially assigned server, maintaining session persistence.
Static
Pros:
Session Persistence ๐: Maintains user session data.
Better User Experience ๐: No session timeouts or data loss.
Simpler App Design ๐ ๏ธ: Assumes user requests hit the same server.
Cons:
Potential Imbalance โ๏ธ: Uneven load distribution.
Scaling Issues ๐: Challenges when adding new servers.
Server Failure Impact ๐ฅ: Disruptions if a sticky server fails.
Use Cases:
Web Apps with Sessions ๐: Maintains user carts and preferences.
Authentication Systems ๐: Keeps users logged in across requests.
Multi-step Forms ๐: Remembers data across form pages.
Streaming Services ๐ฅ: Consistent server connection during streams.
Online Gaming ๐ฎ: Tracks player states and scores consistently.
Example (NGINX+):
upstream backend {server s1.dmn.com;server s2.dmn.com;server s3.dmn.com;stickyย cookieย srv_id expires=2h
domain=.dmn.com path=/;}
2.3.ย โ๏ธ๐Weighted Round Robin
Distributes requests based on assigned server weights, favoring servers with higher capacities or priorities.
Static
Pros:
Adaptive Distribution ๐: Suits servers with different capacities.
Flexibility ๐: Adjusts weights as server performance changes.
Efficient โ๏ธ: Maximizes resource utilization without overloading.
Cons:
Complexity ๐งฉ: Requires monitoring and weight adjustments.
Potential Imbalance โ ๏ธ: Incorrect weights can lead to overloads.
Use Cases:
Mixed Server Capacities ๐ข: When servers have varying resources.
Dynamic Environments ๐ช๏ธ: Adapting to changing server performance.
Traffic Prioritization ๐ฆ: Directing more traffic to higher-performing servers.
Example (NGINX):
upstream backend {ย ยserver s1.dmn.com weight=3;ย ยserverย s2.dmn.com weight=2;
serverย s3.dmn.comย weight=1;}
2.4. ๐#๏ธโฃIP Hash
Distributes requests based on a hash of the client's IP address, ensuring consistent routing to the same server for a specific IP.
Static
Pros:
Session Persistence ๐: Clients consistently directed to the same server.
Predictable Distribution ๐: Based on client IP hash, ensuring even load.
Cons:
Limited Flexibility โ๏ธ: Hard to adjust once set up.
Imbalance Risk โ ๏ธ: Some servers might get more traffic if certain IP ranges are more active.
Use Cases:
Stateful Applications ๐: Where session data needs to be retained.
Geo-specific Content ๐: Serving content based on client's geographic location.
Security & Monitoring ๐ก๏ธ: Easier tracking and management of client sessions.
Example (NGINX):
upstream backend {ip_hash;ย ยserver s1.dmn.com weight=3;
serverย s2.dmn.com weight=2;
serverย s3.dmn.comย weight=1;}
2.5. ๐ณ#๏ธโฃGenericย Hash
Distributes requests using a hash of customizable inputs, offering flexible and consistent routing based on various data points.
Static
Pros:
Versatility ๐: Hashes on diverse inputs, including text, variables, or combinations like IP-port pairs or URIs.
Uniform Distribution ๐: Aims for even distribution across servers.
Cons:
Complexity ๐งฉ: Requires careful selection of hash function.
Potential Imbalance โ ๏ธ: Hash collisions or poor hash functions can skew distribution.
Use Cases:
Custom Inputs ๐ ๏ธ: Hash based on specific application data or headers.
Dynamic Environments ๐ช๏ธ: Where inputs for distribution change frequently.
Cache Distribution ๐พ: Ensuring cached content is evenly distributed.
Example (NGINX):
upstream backend {hash $request_uri;ย ยserver s1.dmn.com weight=3;
serverย s2.dmn.com weight=2;
serverย s3.dmn.comย weight=1;}
2.6.ย ๐๐ฝLeast Connections
Directs traffic to servers with the fewest active connections, optimizing for server availability.
Dynamic
Pros:
Adaptive ๐: Directs traffic to less-busy servers.
Efficiency โ๏ธ: Maximizes server utilization without overburdening.
Cons:
Delayed Reaction โฑ๏ธ: Might not account for sudden server load spikes.
Potential Overhead ๐: Requires monitoring of active connections.
Use Cases:
Varying Server Capacities ๐ข: Balances load in mixed-capacity environments.
High Traffic Sites ๐ฆ: Distributes large volumes of requests effectively.
Real-time Applications ๐ฎ: Where quick response times are crucial.
Example (NGINX):
upstream backend {least_conn;server s1.dmn.com;server s2.dmn.com;server s3.dmn.com;}
2.7.ย โฑ๏ธ๐ฝLeast Time
Routes traffic to servers with the quickest response times, ensuring faster user experiences.
Dynamic
Pros:
Fast Responses ๐: Prioritizes quickest servers.
Dynamic Adaptation ๐: Adjusts based on server response times.
Cons:
Monitoring Overhead ๐: Requires continuous tracking of server latencies.
Fluctuation Risk โ ๏ธ: Rapid changes in response times can lead to frequent server switches.
Use Cases:
User Experience ๐๏ธ: Ensures users get the fastest server response.
High Demand Applications ๐ฅ: For services like video streaming where latency matters.
Variable Server Performance ๐: Balances in environments with fluctuating server speeds.
Example (NGINX+):
upstream backend {least_time header;server s1.dmn.com;server s2.dmn.com;server s3.dmn.com;}
โ What combination of load balancing methods are you guys currently implementing in your system?
3. HTTP Status Codes
HTTP status codes are three-digit responses sent by servers to indicate the outcome of a request. They categorize the result into five broad classes: informational (1xx), successful (2xx), redirection (3xx), client errors (4xx), and server errors (5xx). Understanding these codes is crucial as they provide insight into the success or failure of an HTTP request, helping diagnose issues, optimize user experience, and ensure smooth communication between client and server.
Short version:
and more detailed:
1xx: Informational ๐
100 Continue๐ค101 Switching Protocols๐102 Processingโณ103 Early Hints๐ก
2xx: Successful โ
200 OK๐201 Created๐202 Accepted๐203 Non-Authoritative Informationโน๏ธ204 No Content๐ซ205 Reset Content๐206 Partial Contentโณ207 Multi-Status๐208 Already Reported๐ข226 IM Used๐
3xx: Redirection โก๏ธ
300 Multiple Choices๐ค301 Moved Permanentlyโก๏ธ302 Found๐303 See Other๐304 Not Modified๐305 Use Proxy๐ง307 Temporary Redirectโก๏ธ308 Permanent Redirectโก๏ธ
4xx: Client Errors โ
400 Bad Request๐ซ401 Unauthorized๐402 Payment Required๐ฐ403 Forbidden๐ท404 Not Found๐ณ๏ธ405 Method Not Allowedโ406 Not Acceptable๐ซ.407 Proxy Auth Required๐408 Request Timeoutโฐ409 Conflictโ ๏ธ410 Gone๐ณ๏ธ411 Length Requiredโ412 Precondition Failedโ413 Payload Too Large๐ฆ414 URI Too Long๐415 Unsupported Media Typeโ416 Range Not Satisfiable๐ซ417 Expectation Failedโ418 I'm a Teapotโ: April Fools' joke419 Page Expiredโณ420 Method Failure/Enhance Your Calm๐ซ
421 Misdirected Requestโ ย ย ย
422 Unprocessable Entityโ(WebDAV)
423 Locked๐ย (WebDAV)424 Failed Dependencyโ(WebDAV)
425 Too Earlyโฐ426 Upgrade Requiredโฌ๏ธ428 Precondition Requiredโ429 Too Many Requests๐ซ430 HTTP Status Code๐ซ431 Headers Too Large๐440 Login Time-Outโฐ444 No Response๐ซ449 Retry With๐450 Blocked by Parental Controls๐ ย
451 Legal Reasonsโ๏ธ460 Client Closed Connection Prematurely๐ซ
463 Too Many Forwarded IP Addresses๐ซ ย
494 Request Header Too Large๐495 SSL Certificate Errorโ496 SSL Certificate Required๐497 HTTP to HTTPSโ498 Invalid Tokenโ499 Token Required/Client Closed๐ซ
5xx: Server Errors๐จ
500 Internal Server Error๐จ501 Not Implementedโ502 Bad Gateway๐ง503 Service Unavailableโ504 Gateway Timeoutโฐ505 HTTP Version Not Supportedโ506 Variant Also Negotiates๐507 Insufficient Storage๐พ(WebDAV)508 Loop Detected๐(WebDAV)509 Bandwidth Limit Exceeded๐510 Not Extendedโ511 Network Authentication Required๐520 Unknown Errorโ521 Server Is Downโ522 Timeoutโฐ523 Origin Unreachable๐ง524 Timeoutโฐ525 SSL Handshake Failed๐526 Invalid SSL Certificateโ527 Railgun Listener to Origin๐529 Service Overloadedโ ๏ธ530 Site Frozenโ๏ธ598 Network Read Timeoutโฐ599 Network Connect Timeoutโฐ
โ Imagine you're designing a new HTTP status code that indicates a server has understood the request but refuses to fulfill it, not due to authorization issues but because it deems the request to be potentially harmful or malicious. What would you name this status code, and how would you differentiate its use from the existing 403 Forbidden and 451 Unavailable For Legal Reasons codes?
4. Fundamental Latency Metrics to Remember
The numbers provided are approximate, based on figures from Peter Norvigโs article: http://norvig.com/21-days.html#answers.
It's essential to have a general understanding of the orders of magnitude rather than the exact values for the following reasons:
Performance Optimization: Helps identify system bottlenecks and areas for improvement.
System Design: Guides decisions about data placement and communication strategies in distributed systems.
Realistic Expectations: Sets achievable benchmarks for system operations.
Efficient Coding: Enables developers to write latency-aware code, reducing wasteful operations.
Debugging: Assists in quickly spotting performance anomalies.
User Experience: Directly impacts how users perceive application responsiveness.
Cost Efficiency: Faster operations can lead to savings, especially in cloud environments.
Educated Trade-offs: Allows for informed decisions when balancing performance, cost, and reliability.
โ Guys, if you had to design a real-time collaborative document editing platform (similar to Google Docs) where multiple users from around the world can edit a document simultaneously, which latency numbers would be most critical to consider, and how would they influence your design choices to ensure a seamless user experience?
5. Git commands. Part 1 (21 commands).
Use case: Developing a new feature for a web application.
Git config: Before starting, Alice sets her Git username and email.
git config --global user.name "Alice Smith" git config --global user.email "alice.smith@example.com"Git init: Alice initializes a new Git repository for her project.
git init my-web-appGit clone: Bob wants to collaborate with Alice. He clones her repository.
git clone https://github.com/alice/my-web-app.gitGit status: Alice checks the status of her files.
git statusGit add: Alice adds a new file to the staging area.
git add index.htmlGit commit: Alice commits her changes with a message.
git commit -m "Added homepage."Git push: Alice pushes her changes to the remote repository.
git push origin masterGit branch: Bob creates a new branch to work on a feature.
git branch feature-navbarGit checkout: Bob switches to his new branch.
git checkout feature-navbarGit merge: Alice merges Bob's feature branch into the master branch.
git merge feature-navbarGit pull: Bob pulls the latest changes from the remote repository.
git pull origin masterGit log: Alice views the commit history.
git logGit show: Bob checks the details of the last commit.
git showGit diff: Alice checks the differences between her working directory and the last commit.
git diffGit tag: Alice tags the current commit as a new release.
git tag v1.0Git rm: Bob removes a file from the repository.
git rm old-file.txtGit stash: Alice temporarily saves her changes to work on something else.
git stashGit reset: Bob undoes the last commit, keeping the changes in the working directory.
git reset HEAD~1Git revert: Alice undoes a specific commit by creating a new commit.
git revert commit_idGit remote: Bob checks the remote repositories connected to his local repository.
git remote -vGit fetch: Alice fetches the latest changes from the remote repository without merging.
git fetch originโ Guys, imagine you're working on a feature branch in Git and you've made several commits. You then realize that one of the commits in the middle introduced a critical bug. Without reverting or affecting the subsequent commits, how would you use Git commands to isolate and address just that specific commit?








