阿里、蚂蚁、晟腾、中科加禾精彩分享 AI 基础设施洞见,现购票可享受 9 折优惠 |AICon 了解详情
写点什么

Best Practices For Horizontal Application Scaling

作者:Dzone

  • 2020-04-03
  • 本文字数:4904 字

    阅读完需:约 16 分钟

A best practice is a technique or methodology that, through experience and research, has proven to reliably lead to superior results. In this blog post, I will talk about few best practices that I have learned over the years which might help you in designing scalable web applications.


But before we talk about scaling best practices, we should define the meaning of scalability. Most of the people confuse scalability with performance. Performance refers to the capability of a system to provide a certain response time. Scalability can be defined as ease with which a system or component can be modified to fit the problem area in such a way that the system can accommodate increased usage, increased datasets, and remains maintainable. A system can be performant but might not be scalable. For example, a web application can be very responsive and fast for 100 users and 1GB of data, but it will not be considered scalable if it can’t maintain the same speed with 100 times the data with 100 times the users. You achieve scalable architecture when you can handle more load by adding more of the same stuff. You want to be able to scale by throwing money at a problem which means throwing more boxes at a problem as you need them.

Types of Scaling

Vertical scaling : It is about adding more power to the single machine i.e. faster CPU , more RAM , SSD etc . Vertical scalability has a limit and the cost increases exponentially.


Horizontal scaling : It is about handling more requests and load by adding more machines. It requires special attention to application architecture.


Below is the image taken from book " Building Scalable Web Sites by Cal Henderson " which clearly shows that with vertical scaling cost increase exponentially whereas with horizontal scalability cost is linear.


Note : This blog is not about how OpenShift supports horizontal scaling. If you want to learn about that you can read couple of very good blogs from Steve on how OpenShift supports AutoScaling and Manual scaling .

Horizontal Scaling Best Practices

Now I will list some of the best practices which will help you scale your web application. Most of these are generic and can be applied to any programming language.


  1. Split Your Monolithic Application


  2. The idea behind this practice is to split the monolithic application into groups of functionally related services which can be maintained and scaled together. You can do this via SOA(Service Oriented Architecture) , ROA(Resource Oriented Architecture) , or by just following good design practices, idea is just to split big monolithic application into smaller applications based on functionality. For example, all user related services can be grouped into one set, search in another, etc. Web scalability is about developing loosely coupled systems. It should be designed in such a way that many independent components communicate with each other. If one component goes down, it should not effect the entire system. This help avoids “single points of failure”. The more decoupled unrelated functionality can be, the more flexibility you will have to scale them independently of one another. As services are now split, the actions we can perform and the code necessary to perform them are split up as well. This means that different teams can become experts in subsets of systems and don’t need to worry about other parts of system. This not only helps in scaling application tier but helps in scaling database tier as well. As rather using single database and going with one choice , you can choose different databases for different needs.

  3. Use Distributed Caching


  4. Distributed caching can help in horizontal scalability of a web application by avoiding access to a slow database or filesystem and instead retrieves data directly from the fast local memory. This helps the application in scaling linearly, just by adding more nodes to the cache cluster. A Java web application using a distributed cache can store frequently accessed data such as results of a database query or computation intensive work in a cache. Applications can use Memcached or Infinispan to create distributed cache cluster. Caching is all about minimizing the amount of work a system does. It is advisable that you put caching in its own tier rather than using application servers machines. This will help you in scaling the caching tier independently of application tier.

  5. Use CDN


  6. You should use CDN(Content delivery network) to offload traffic from your web application. A content delivery network or content distribution network (CDN) is a large distributed system of servers deployed in multiple data centers across the Internet. The goal of a CDN is to serve content to end-users with high availability and high performance. CDNs are mostly used for delivering static content like css , images , javascript, static html pages near to the user location. It will find the best possible server which can fulfill the request in the least amount of time by fewer network hops, highest availability, or fewer request. Your application can leverage either Akamai or Amazon CloudFrond for CDN capabilities.

  7. Deploy Shared Services To Their Own Cluster


  8. Some applications use file systems to save files uploaded by users, or to store configuration files. You need to replicate these files to all the nodes so that all nodes can use them. With more nodes added, copying files among server instances will occupy all the network bandwidth and consuming considerable CPU resources. To work in a cluster, the solution is to use the database in place of external files, or SAN or use Amazon S3. This will help achieve better scalability.

  9. Go Async


  10. The next best practice to scaling is the use of asynchronous calls. If two components X and Y call each other synchronously, then X and Y are tightly coupled, and then either both of them will scale or none of X and Y will scale. This is a characteristic of tightly coupled systems - to scale X, you must scale Y as well and vice versa. For example, it is very common that after user registration email is sent to the user for verification. Now if you tightly couple the user registration service and email service together than scalability of user registration service will be dependent on tje email service. But if you do it asyncronously either through a queue, multicast messaging, or some other means, then you can continue registering users, untill you are sure that the verification email will be sent to user. Synchronous calls stop the entire program execution waiting for a response, which ties all services together leading to cascading failures. This not only impacts scalability but availability of the system as well. In other words, if Y is down then X is down. With async design, X and Y now have independent availability characteristics - X can continue to move forward even if Y is down.

  11. Parallelize The Task


  12. There are times when you can divide a single threaded task to multiple smaller tasks which can be run in parallel not only on a single machine but on a cluster of machine. A single thread of tasks will be the scalability bottleneck of the system. Java 7 introduced fork/join framework that helps you take advantage of multiple processors. It is designed for work that can be broken into smaller pieces recursively. The goal is to use all the available processing power to enhance the performance of your application.

  13. Don’t Store State in the Application Tier


  14. The golden rule to achieve scalability is not storing state in the application tier but storing state in the database so that each node in the cluster can access the state. Then you can use a standard load-balancer to route incoming traffic. Because all application servers are equal and does not have any transactional state, any of them will be able to process the request. If we need more processing power, we simply add more application servers.

  15. Use Non-Blocking IO


  16. The java.nio package allows developers to achieve greater performance in data processing and offers better scalability. The non-blocking I/O operations provided by NIO and NIO.2 boosts Java application performance by getting “closer to the metal” of a Java program, meaning that the NIO and NIO.2 APIs expose lower-level-system operating-system (OS) entry points. In a web application, traditional blocking I/O will use a dedicated working thread for every incoming request. The assigned thread will be responsible for the whole life cycle of the request - reading the request data from the network, decoding the parameters, computing or calling other business logical functions, encoding the result, and sending it out to the requester. Then this thread will return to the thread pool and be reused by other requests. With NIO, multiple HTTP connections can be handled by a single thread and the limit is dependent on amount of heap memory available. You can turn on NIO in Tomcat by changing the protocol attribute ofelement as shown below


<Connector    protocol="org.apache.coyote.http11.Http11NioProtocol"    port="80"    redirectPort="8443"    connectionTimeout="20000"    compression="on" />
复制代码

References

  1. http://www.allthingsdistributed.com/2006/03/a_word_on_scalability.html

  2. http://searchsoftwarequality.techtarget.com/definition/best-practice

  3. http://www.amazon.co.uk/Building-Scalable-Web-Sites-Henderson/dp/0596102356

  4. http://www.infoq.com/articles/ebay-scalability-best-practices

  5. http://www.amazon.com/Scalability-Rules-Principles-Scaling-Sites/dp/0321753887

  6. Image source http://www.flickr.com/photos/amanda47/435068244/

What’s Next?


2020-04-03 11:22991

评论

发布
暂无评论
发现更多内容

架构训练营模块一作业

现在不学习马上变垃圾

#架构实战营

2022-12-07:删除重复的电子邮箱。删除重复数据后,id=3的数据被删除。请问sql语句如何写? DROP TABLE IF EXISTS `person`; CREATE TABLE `per

福大大架构师每日一题

数据库 福大大

数据库到底应该如何存储密码?

Java永远的神

数据库 程序员 程序人生 后端 架构师

【沙丘大会回顾】九科信息研发中心自动化负责人郑文茂分享央企数字员工实践案例

九科Ninetech

ChatGPT 加图数据库 NebulaGraph 预测 2022 世界杯冠军球队

NebulaGraph

图数据库 世界杯 AI预测

FL Studio21正式版本发布更新附送85款主题下载

茶色酒

FL Studio 21 FL Studio21

百亿节点、毫秒级延迟,携程金融基于 NebulaGraph 的大规模图应用实践

NebulaGraph

风控 风控模型 电商风控

架构--模块七 作业

李某人

架构训练营

提供多种数据看板,瓴羊Quick BI全面提升企业可视化分析能力

小偏执o

模块一作业

陈天境

微信业务架构图 & 学生系统技术架构图

白杨

主数据管理实施四部曲概论

用友BIP

设计原则

Lemoon Can

面向对象设计原则 设计原则

FL Studio2023新版本功能爆料将引入4款全新插件!创作力UP!

茶色酒

FL Studio

阿里云祝顺民:生而为云,连接增长

云布道师

阿里云 云网络

架构实战营-模块一作业

氢原子

#架构实战营

重写事件抛发接收机制原理

千锋IT教育

架构实战 1 - 微信业务架构图-学生管理系统技术选型

架构实战营 「架构实战营」

架构训练模块1

KING

模块一作业

unique

携程全球合作伙伴峰会商旅分论坛:以五大中心构建“人数智”服务能力体系

携程商旅

架构实战营模块一_作业

原城

架构实战营 #架构实战营 架构师实战营 「架构实战营」

掌握高并发系统设计,面试弯道超车

小小怪下士

Java 面试 系统设计 后端 高并发

flex弹性盒子中flex-grow与flex的区别

千锋IT教育

面试常问的高并发系统设计,我们到底该怎么学?

程序员小毕

程序员 面试 后端 高并发 架构设计

如何通过“推送文案的千人千面”有效提升用户转化和留存

极光JIGUANG

极光推送 用户运营

Flink架构与应用漫聊

数新网络官方账号

SCRM是什么,SCRM和CRM区别?

优秀

CRM scrm

全面进化!Apache Doris 1.2.0 Release 版本正式发布|版本通告

SelectDB

数据库 大数据 开源 数据分析 Doris

结合RocketMQ源码说说并发编程的三大神器

程序员小毕

源码 程序员 RocketMQ 后端 架构师

无刷直流电机最强科普(收藏版)

元器件秋姐

发展史 电机 BLDC应用 电子工程师 无刷直流电机

Best Practices For Horizontal Application Scaling_其他_InfoQ精选文章