Scalability and High Availability Flashcards
What is scalability?
The ability of an app to handle and withstand the increased load without sacrificing the latency.
For instance, if your app takes x seconds to respond to a user request. It should take the same x seconds to respond to each of the million concurrent user requests on your app.
The backend infrastructure of the app should not crumble under a load of a million concurrent requests.
What is the latency?
The time taken to process the request & respond
No matter how much the traffic load on a system builds up, the latency should not go up
Two Types of latency
- Network Latency(The time taken to send the packet from point A to point B. )- To cut down N/W latency, Businesses use CDN(Content Delivery Network) and try to deploy their servers across the globe as close to the end-user.
- Application Latency: The time taken to process the user request
How to reduce application latency?
Run Stress and Load test on application and scan for bottlenecks
What is vertical Scaling?
Adding more power to the existing resources.
The first step towards scaling up when the traffic increases.
Doesn’t require code refactoring or any complex configurations at a code level.
There is a limit for vertical scaling.
What is horizontal Scaling?
Adding more hardware to the existing pool of hardware resource pool.
No limit to horizontally scaling
What is cloud elasticity?
If the site has a heavy traffic influx more server nodes get added & when it doesn’t the dynamically added nodes are removed.
What are the points to consider when running code in a distributed environment?
The code needs to be stateless. No Static instance in the class.
Major bottlenecks for scaling an app
- Database: Apps horizontally scaled out but all communicating with one single DB. This is a bottleneck scenario. Make use of Database Partitioning, Sharding, or multiple database servers to make module efficient.
2.Application Architecture: A common architectural mistake is not using asynchronous processes & modules where ever required rather all the processes are scheduled sequentially. - Not using Caching in application wisely
- Inefficient configuration and setup of LB
- Adding business logic to DB
- Not picking up the right DB
Need transactions & Strong Consistency- Relational DB
HA and Less Consistency- NoSQL - Bad Coding Standards
Steps to Improve the Scalability of the app
- Profiling(Memory Profiling, Code Profiling)
- Caching(Cache wisely. Cache everywhere. Cache all static content. Hit the DB when it is really required. Try to serve all read requests from the cache. Use a write-through Cache( Write in both DB and Cache while updating/inserting)
- CDN (Using a CDN further reduces the latency of the application due to the proximity of the data from the requesting user)
- Data Compression (Use apt algorithms to compress the data. Store the data in compressed format. Compressed data consumes less bandwidth and download speed at the client becomes faster)
- Avoid unnecessary client-server requests.
Parameters to be taken into account while scalability testing:
- CPU Usage
- Network Bandwidth Consumption
- Throughput
- No of request processed within a stipulated time
- latency
- Memory usage of the program
- End-user experience when the system is under heavy load
What is High Availability?
The ability of a system to stay online despite infrastructure failures in real-time.
To make a system HA, they are made fault-tolerant using redundancy.
Reasons for System failures
- Software Crashes
- Hardware Failures( Overloaded CPU,Overloaded CPU, RAM, hard disk failures, nodes going down. Network outages.)
- Human Errors: Flawed configurations & stuff.
- Planned Downtime
What is fault Tolerant?
The ability of a system to stay up despite taking hits.
An FT System is equipped to handle faults.
In case of these internal failures, the system could work at a reduced level but it will not go down entirely.
Social Media application.
In the case of backend node failures, a few services of the app such as image upload, post likes, etc. may stop working. But the application as a whole will still be up.
This approach is called Fail Soft.
Microservice architecture is the best example of this.
What is redundancy?
Duplicating the components or instances & keeping them on standby to take over in case of active instance goes down.
This approach is called Active-Passive HA Mode.