Distributed Application Architecture Patterns

8.2 Colocate

Improve network reliability by decreasing the distance between services with high coupling

This pattern was explicitly defined only by Wilder [14, p. 109], but is directly leveraged by other authors in other patterns (see §§ 8.3, 5.1, 5.2 and 11.1).

8.2.1 Context

Heavy traffic between two parties leads to additional network latency and unreliability, which has a significant performance impact.

8.2.2 Solution

Decrease the network distance between parties with high coupling (see fig. 21). This might include deploying services to the same node, moving services to the same LAN or data centre, or moving services geographically closer to their clients.

Figure 21: Colocate

8.2.3 Potential issues

Moving services together might make the system less resilient to failures, as they might share the same physical resources (see § 7.1).

8.2.4 Example

Searching in ExampleEshop is a critical part of the system, as it is the primary way users find products. The search index is partitioned across multiple data stores to handle the load. However, this means that the amount of network traffic needed to search the index is much higher than if the index was stored locally and that the speed of the slowest response dictates the speed of the search. Furthermore, with more partitions, the chance of a network request failing increases. To combat this, they moved the partitioning logic into a separate component that they deployed close to the data stores. This way, most of the network requests are fast and more reliable, which improves the overall search performance and reliability.

This idea of placing services close to each other is a common theme in several other patterns.

  1. A Sidecar builds upon this pattern to provide additional, language-agnostic functionality to a service by deploying it alongside the main application (see § 5.1)

  2. Similarly, an Ambassador can be used to handle network communication on behalf of a service, offloading common connectivity tasks (see § 5.2)

  3. An Anti-Corruption Layer, although it does not necessarily need to be colocated, will still benefit from close proximity to at least one of the involved parties (see § 11.1)