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
- Defines standard API for service discovery, not tied to specific backends
- Two core methods: lookup for one-time queries, subscribe for real-time updates
- Subscribe returns CancellationToken for managing long-lived service instance monitoring
- Backend implementations must conform to ServiceDiscovery protocol with deadline support
- Community-driven project actively seeking backend implementation contributions
Swift Service Discovery establishes a vendor-neutral standard for service discovery in Swift server apps, letting teams swap backends without rewriting application code.
About This Article
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.
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.
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.