Sunday, March 18, 2018

Designing Distributed System



https://zhuanlan.zhihu.com/p/34146314
单点模式之挎斗模式 - Sidecar

挎斗模式设计案例:向传统服务添加HTTPS

例如,考虑一个遗留的Web服务。 多年前,当它建成时,内部网络安全并不是公司的优先事项,因此,应用程序仅通过未加密的HTTP服务处理请求,而不是HTTPS。 由于最近的安全事件,该公司已经要求所有公司网站使用HTTPS。 但是不幸的是这个应用程序的源代码是用公司的构建系统的旧版本构建的,该系统已经不再起作用。这个HTTP应用程序以二进制文件形式在一个容器中运行。但是,将HTTPS添加到此应用程序的任务显然更具挑战性。团队成员要在使用挎斗模式和试图复活旧版系统并将应用程序的源代码移植到新版系统之间作决定。

挎斗模式在这种情况下的应用很简单。遗留的Web服务被配置为仅在本地主机(127.0.0.1)上提供服务,这意味着只有与服务器共享本地网络的服务才能够访问该服务。通常情况下,这不是一个实际的选择,因为这意味着没有人可以访问Web服务。但是,除了遗留容器之外,使用挎斗模式,我们添加一个nginx挎斗容器。这个nginx容器与传统Web应用程序位于相同的网络名称空间中,因此它可以访问在本地主机上运行的服务。与此同时,此nginx服务可以在pod的外部IP地址上终止HTTPS流量,并将该流量代理到旧式Web应用程序
挎斗模式可以用来提供新功能,在不改变现有应用程序的情况下增强传统应用程序的功能。对于图4所示的挎斗模式,同样有两个容器:作为服务的应用程序的容器和作为配置管理器的容器。这两个容器组合在一起成为一个容器,它们共享一个目录——配置文件的位置。

使用挎斗模式做动态配置

挎斗模式可以更多地用于适配和监控。它也可以作为一种手段,以简化的模块化方式为你的应用程序实现完整的逻辑。举个例子,想象一下构建一个围绕git工作流构建的简单的平台即服务(PaaS)。一旦部署了PaaS,只需将新代码推送到Git存储库,就可以将代码部署到正在运行的服务器上。我们将看到挎斗模式如何使这个PaaS非常简单直观。
如前所述,在挎斗模式中有两个容器:主应用容器和挎斗。在我们简单的PaaS应用程序中,主容器是实现Web服务器的Node.js服务器。 Node.js服务器进行了检测,以便在更新新文件时自动重新加载服务器。这是使用nodemon工具完成的。
sidecar容器与主应用程序容器共享一个文件系统,并运行一个简单的循环,使文件系统与现有的Git存储库同步。 Node.js应用程序和Git同步挎斗共同被安排并部署在一起以实现我们简单的PaaS(图5)。 一旦部署完毕,每次将新代码推送到Git存储库时,代码都会由挎斗自动更新并由服务器重新加载。

https://zhuanlan.zhihu.com/p/34159639
上次我们介绍了挎斗模式,是一个预先存在的容器增加一个容器以添加功能。 本章介绍大使模式(Ambassador),大使容器是代理应用程序容器与其他地方之间的交互。 与其他单节点模式一样,这两个容器也是紧密联系在一起,共生配对部署在一台机器上。

https://docs.microsoft.com/en-us/azure/architecture/patterns/ambassador
Put client frameworks and libraries into an external process that acts as a proxy between your application and external services. Deploy the proxy on the same host environment as your application to allow control over routing, resiliency, security features, and to avoid any host-related access restrictions. You can also use the ambassador pattern to standardize and extend instrumentation. The proxy can monitor performance metrics such as latency or resource usage, and this monitoring happens in the same host environment as the application.

https://docs.microsoft.com/en-us/azure/architecture/patterns/sidecar
Deploy components of an application into a separate process or container to provide isolation and encapsulation. This pattern can also enable applications to be composed of heterogeneous components and technologies.
This pattern is named Sidecar because it resembles a sidecar attached to a motorcycle. In the pattern, the sidecar is attached to a parent application and provides supporting features for the application. The sidecar also shares the same lifecycle as the parent application, being created and retired alongside the parent. The sidecar pattern is sometimes referred to as the sidekick pattern and is a decomposition pattern.

Applications and services often require related functionality, such as monitoring, logging, configuration, and networking services. These peripheral tasks can be implemented as separate components or services.
If they are tightly integrated into the application, they can run in the same process as the application, making efficient use of shared resources. However, this also means they are not well isolated, and an outage in one of these components can affect other components or the entire application. Also, they usually need to be implemented using the same language as the parent application. As a result, the component and the application have close interdependence on each other.
If the application is decomposed into services, then each service can be built using different languages and technologies. While this gives more flexibility, it means that each component has its own dependencies and requires language-specific libraries to access the underlying platform and any resources shared with the parent application. In addition, deploying these features as separate services can add latency to the application. Managing the code and dependencies for these language-specific interfaces can also add considerable complexity, especially for hosting, deployment, and management.
Solution
Co-locate a cohesive set of tasks with the primary application, but place them inside their own process or container, providing a homogeneous interface for platform services across languages.

https://zhuanlan.zhihu.com/p/34171372
在适配器模式中,适配器容器用于修改应用程序容器的接口,以便它符合所有应用程序预期的某个预定义接口。例如,适配器可能确保应用程序实现一致的监控界面,或者它可以确保日志文件始终写入标准输出或其他任何形式的约定。
最后,微服务的解耦可以实现更好的扩展。由于每个组件都已分解为自己的服务,因此可以独立进行扩展。大型应用程序中的每项服务都以相同的速度增长,或者具有相同的缩放方式,这种情况很少发生。有些系统是无状态的,可以简单地进行水平缩放,而其他系统则保持状态并需要分片或其他缩放方法。通过分离每个服务,每个服务可以使用该方法进行最适合的缩放。当所有的服务都是单一“巨石”的一部分时,这是不可能的。
但是,当然微系统设计的方法也存在不足之处。最主要的两个缺点是,由于系统变得更加松散耦合,发生故障时调试系统显得更加困难。你不能再将单个应用程序加载到调试器中,并确定出错的原因。任何错误都是经常在不同机器上运行的大量系统的衍生品。在调试器中复现这种环境非常具有挑战性。作为推论,基于微服务的系统也很难设计和架构。基于微服务的系统使用多种服务之间的通信方法;不同的模式(例如同步,异步,消息传递等);以及服务之间多种不同的协调和控制模式。

Scatter/Gather
- Solr, Search



Labels

Review (572) System Design (334) System Design - Review (198) Java (189) Coding (75) Interview-System Design (65) Interview (63) Book Notes (59) Coding - Review (59) to-do (45) Linux (43) Knowledge (39) Interview-Java (35) Knowledge - Review (32) Database (31) Design Patterns (31) Big Data (29) Product Architecture (28) MultiThread (27) Soft Skills (27) Concurrency (26) Cracking Code Interview (26) Miscs (25) Distributed (24) OOD Design (24) Google (23) Career (22) Interview - Review (21) Java - Code (21) Operating System (21) Interview Q&A (20) System Design - Practice (20) Tips (19) Algorithm (17) Company - Facebook (17) Security (17) How to Ace Interview (16) Brain Teaser (14) Linux - Shell (14) Redis (14) Testing (14) Tools (14) Code Quality (13) Search (13) Spark (13) Spring (13) Company - LinkedIn (12) How to (12) Interview-Database (12) Interview-Operating System (12) Solr (12) Architecture Principles (11) Resource (10) Amazon (9) Cache (9) Git (9) Interview - MultiThread (9) Scalability (9) Trouble Shooting (9) Web Dev (9) Architecture Model (8) Better Programmer (8) Cassandra (8) Company - Uber (8) Java67 (8) Math (8) OO Design principles (8) SOLID (8) Design (7) Interview Corner (7) JVM (7) Java Basics (7) Kafka (7) Mac (7) Machine Learning (7) NoSQL (7) C++ (6) Chrome (6) File System (6) Highscalability (6) How to Better (6) Network (6) Restful (6) CareerCup (5) Code Review (5) Hash (5) How to Interview (5) JDK Source Code (5) JavaScript (5) Leetcode (5) Must Known (5) Python (5)

Popular Posts