Last updated 4 months ago

Ecosystems are Polylith's solution to scaling. They are a collection a systems collaborating to offer a unified set of functionality to the outside world.

Sometimes a single system isn't enough to meet our performance or operational needs. That's when we have to scale our solution horizontally, by getting multiple systems working together in an ecosystem.

Two Polylith systems ready to be connected into an ecosystem

There are two reasons to add a new system into an ecosystem:

  1. when you've hit a performance/scalability bottleneck

  2. to gain operational benefits (for example, to separate your batch processing from your main system)

In Polyith, we don't need to create new systems to structure our domain into managable and encapsulated modules. That's what components are for.

System B connected to an endpoint offered by system A's API

The simplest ecosystem we can visualise involves just two systems. We can imagine them being connected via a "cable" which extends from an external dependency in a component in system B to an endpoint in system A's base.

One of the advantages with Polylith is how easy it is to share components across multiple systems within a workspace. It's a component's functional and stateless nature that makes it perfect for reuse. For example, if both system A and system B need to access the same database, then they can use the same database component.

It can be a useful pattern to make just one system act as the API for an entire ecosystem. This makes use of the same encapsulation concept as the interface and implementation layers in a component and base. It allows us to offer a single place to access the ecosystem's functionality, whilst hiding unnecessary implementation details.

But what is it like to work with Polylith?

Hopefully the building block metaphor has given you a high-level understanding of the Polylith architecture.

Now let's take a closer look at how Polylith structures your code, and gives you a workspace to play with these building blocks.