架构师训练营第四周作业
一个典型的大型互联网应用系统使用了哪些技术方案和手段,主要解决什么问题?请列举描述。
问题
一个大型的互联网应用,会遇到如下的问题:
面对大流量,因为内存资源或CPU资源或永久数据储存资源紧张或IO瓶颈而应用性能明显下降,甚至造成系统不可用,特别是数据库的瓶颈。
因为用户多,所以多短的系统不可用(不管是因为维护还是因为系统出问题),都会造成大量损失。
安全攻击。
团队合作困难,代码耦合严重。
代码复杂,添加新的功能难度大而复杂
解决方法
垂直伸缩
解决问题:高性能(减少响应时间)
DNS (Domain Name System)
Route traffic to different servers.
Geolocation-based: 不同地区部署服务器,将访问用户的请求引导到最近的服务器
weighted round-robin: 方便A/B testing,按照集群大小分配流量
解决问题:高性能(减少响应时间)帮助水平伸缩。
CDN (Content Delivery Network)
CDN是缓存服务,缓存一些热门的静态的资源。这些静态资源例如图片是很大。让用户可以就近获得这些缓存的资源。
解决问题:高性能(减少响应时间)
Load Balancer
将客户请求分配到不同到计算资源,比如服务器,数据库。
Session persistence - Issue cookies and route a specific client's requests to the same instance when the web apps do not keep track of sessions
SSL termination - Decrypt incoming requests and encrypt server responses so backend servers do not have to perform these potentially expensive operations
例子:NGINX
解决问题:高性能(减少响应时间)帮助水平伸缩。
反向代理
A reverse proxy is a web server that centralizes internal services and provides unified interfaces to the public. Requests from clients are forwarded to a server that can fulfill it before the reverse proxy returns the server's response to the client.
缓存response for cached requests, Serve static content directly, Increased scalability and flexibility - Clients only see the reverse proxy's IP, allowing you to scale servers or change their configuration
解决问题:高性能(减少响应时间)帮助水平伸缩。
业务拆分,中台化,微服务
解决问题:减少代码耦合,减低开发难度,通过复用微服务增强可扩展性
系统分层
解决问题:增强可扩展性
Redundancy
解决问题:增强可用性 (多余的备份消除single point of failure)
异步
使用消息队列,可以解耦,增强可扩展性,提高性能,减低代码开发难度。
Backpressure can help by limiting the queue size, thereby maintaining a high throughput rate and good response times for jobs already in the queue. Once the queue fills up, clients get a server busy or HTTP 503 status code to try again later. Clients can retry the request at a later time, perhaps with exponential backoff.
解决问题:高性能
分布式,集群
解决问题:高性能,可扩展性
缓存
解决问题:高性能
———————————————————————————————————————————————
数据库相关技术方案:
主从,主从复制,主主复制
尤其适合读多写少的系统。主从复制可以读写分离。
解决问题:高性能(减少响应时间)高可用(当主数据库宕机是,从库/其他主库可以继续服务)
分数据库 Functional partitioning
Splits up databases by function.
解决问题:高性能
分片
Sharding distributes data across different databases such that each database can only manage a subset of the data.
解决问题:高性能
NoSQL
Key-value store:
A key-value store generally allows for O(1) reads and writes and is often backed by memory or SSD. Key-value stores provide high performance and are often used for simple data models or for rapidly-changing data, such as an in-memory cache layer. 例子:Redis, Memcached.
Document store:
A document store is centered around documents (XML, JSON, binary, etc), where a document stores all information for a given object. Document stores provide APIs or a query language to query based on the internal structure of the document itself. 例子:MongoDB, ElasticSearch (全文搜索)
Wide Column Store:
例子:HBase, Cassandra
解决问题:高性能,more scalable
———————————————————————————————————————————————
评论