Domain-focused design with value-added services and domain gateways at SoundCloud

Two articles were recently published to describe the evolution of SoundCloud’s service architecture towards the implementation of domain gateways, with a stop at value-added services along the way. The authors describe how these domain-driven design-based models helped reduce duplication and streamline business and authorization logic.

A value-added service is a service responsible for providing aggregate entities to its callers. Domain gateways make it possible to manage the same entity on different domains.

According to the authors, SoundCloud’s first service architecture had two service layers: edge services retrieved all data from core services. Each peripheral service orchestrates all of its calls and is also responsible for authorization. Eventually, this pattern led to duplication of code and logic as different services evolved to use the same data in slightly different ways.

The authors write that the second evolutionary step in the enterprise services architecture was to add a third middle layer implementing the Value-Added Services (VAS) model. Such a shift to value-added services has made it possible to better distribute responsibilities. The edge layer provides API gateway functionality and caters to specific customer needs, while the VAS layer consumes core service data, processing it into aggregated entities. Edge layer services then consume these aggregates.

Source: https://developers.soundcloud.com/blog/service-architecture-2

A model such as VAS has some drawbacks, which the authors identified as a larger service landscape and increased network latencies due to the extra hops introduced by new intermediate services. Instead, they considered using shared libraries and concluded that a VAS layer was better for them.

Support for partial responses in value-added services allows the amount of data returned to be tailored to each customer’s needs. Partial responses can also reduce the number of network calls, but the authors say SoundCloud’s goal is to manage complexity at the device layer.

The authors add that their value-added services eventually grew to include the ability to edit entity data. Separate interfaces have isolated write operations from read operations using the concepts of “command” and “request”, which form the core of the well-known command request responsibility segregation (CQRS) model.

As SoundCloud’s VAS grew, it became apparent that the same entities were being used in different domains with different purposes and permission requirements, the authors point out. The Domain Gateway model was the chosen solution to avoid implementing all possible variants in the same service. The authors describe these gateway services as VAS implementations tied to specific business domains.

According to the authors, the duplication introduced by gateway services makes sense “in cases where different domains have very different access patterns and very disjointed feature sets, or when communication and collaboration between teams is difficult”.

These two SoundCloud blog posts follow on from a previous post on the Backends For Frontends pattern, previously covered on InfoQ. An aggregate is a domain-driven design pattern and represents a group of domain objects that can be treated as a single unit. Value-added services and domain gateway models are forms of domain-oriented architectures used in the industry.