Scalability concepts — Part-II
Prerequisite: What is scalability? Why is it require? Different types of scalibilty?
https://medium.com/@jollysrivastava0896/a-word-on-scalability-3ef7a3c5452
https://medium.com/@jollysrivastava0896/scalability-concepts-194f253b4508
In this blog i am trying to explain what it would take to make a web service massively scalable?
By this point in time, our application is massively scaled and is serving a lot of concurrent requests but is getting slower and slower. Reason being: MySQL.
Databases: There are two solutions to this problem. The first being continues to run our MySql beast and do what is called “Sharding”,” Replication”,” SQL tuning”. But the issue with these improvements is that they are expensive and time-consuming.
Another solution is to shift to “NoSQL” or treat your SQL DB as a “NoSQL” one. Why “NoSql”: they are better and easier to scale. Joins will now need to be done in your application code.
Is that it? Will doing this will resolve my issue and make my application runs at a faster rate? The answer is still “NO”.
What can be done now? “Cache”.
Cache: At this point in time we are able to store terabytes of data but our users are still suffering from slower page requests. What can be done?
“In-memory caching”: Memcache or Redis.
A cache is a simple key-value store and acts as a buffering layer between application and data storage. Whenever our application has to read data, it will first read from the cache, and only if it is not present our data storage will be looked up. A cache stores every dataset in RAM and servers our request at a fast rate. Things that we can cache include user sessions, activity streams, fully rendered blog articles, and many more.
Asynchronism: We have now resolved most of our problems. Our system is now horizontally scaled and is able to serve lots of requests at a faster rate.
However, we still can face an issue like my user wants to do some intensive computational task on my website which takes let’s say 10 mins of time. To avoid such a “please wait a while” — situation, asynchronism needs to be done.
As a solution, we can turn dynamic content into a static one. This pre-computing of overall general data can extremely improve websites and makes them more performant and scalable. we can make use of a content delivery network (CDN) that pre-rendered HTML pages. In AWS, we have s3 or CloudFront for this operation.
Another solution is RabbitMQ.RabbitMQ is one of many systems that help to implement async processing. The basic idea is to have a queue of tasks or jobs that a worker can process. If there is something that is time-consuming, we should try to do it asynchronously.