Swift.org Blog Yim Lee Oct 21, 2020

Swift Service Discovery

Article Summary

Yim Lee from Apple's Swift team just open-sourced a game-changer for server-side Swift. If you're building microservices, this standardized approach to service discovery could save you from vendor lock-in.

Apple released Swift Service Discovery, a new open-source package that defines a standard API for service discovery in Swift server applications. Similar to SwiftLog and SwiftMetrics, it provides the interface while backend implementations (DNS-based, key-value stores, etc.) handle the actual functionality.

Key Takeaways

Critical Insight

Swift Service Discovery establishes a vendor-neutral standard for service discovery in Swift server apps, letting teams swap backends without rewriting application code.

The subscribe pattern's approach to handling service instance changes reveals an interesting design choice about push vs. pull architectures.

About This Article

Problem

Swift server applications didn't have a standard way to discover services. Developers had to build custom integrations with backends like DNS or key-value stores, which led to inconsistency across projects.

Solution

Yim Lee and Apple's Swift team built Swift Service Discovery as a protocol-based abstraction layer. It works similarly to SwiftLog and SwiftMetrics, allowing different backends to implement a single `ServiceDiscovery` interface with `lookup` and `subscribe` methods.

Impact

Applications can now swap service discovery backends without changing their code. This reduces vendor lock-in and gives the community a shared standard that welcomes open-source contributions.