Swift on the server offers surprising advantages. A case study by Cultured Code shows that it can be up to four times faster and three times cheaper than Python. There are also disadvantages, such as slow build times.
Swift is primarily used for application development on Apple computers and devices. In principle, the language is also suitable for server-side work, but adoption of server-side Swift remains limited. IBM, an early proponent of the idea, dropped its Kitura Swift framework in 2019.
Still, the appeal of using the same language on both client and server remains. Cultured Code, a popular personal task manager developer for Apple platforms, has documented replacing a Python 2 application on Google App Engine with Swift on Kubernetes (hosted by AWS). DevClass writes about it.
According to Vojtěch Rylko, in charge of development and operations, and CEO Werner Jainek, the switch improved the average response time of the cloud application stores and syncs user data across multiple devices a factor of four, while the average computing power became three times cheaper.
The duo cited the old application’s problem as the lack of static typing in Python, which they said made any change risky. In addition, the system suffered from slow response times and high memory usage, making a complete rewrite the only viable solution.
The new application: Swift with Vapor and Kubernetes
The new Linux application uses Vapor to build HTTP servers and APIs. Vapor uses Apple’s SwiftNIO for asynchronous event-driven network programming.
The application runs on Kubernetes within AWS and consists of about 30,000 lines of code. Build time is about 10 minutes, using Xcode for coding and debugging. The database is AWS Aurora MySQL, Redis is used for temporary data, and the application runs on a small Kubernetes cluster with four nodes. Thanks to the availability of suitable mature libraries, Python is still being used for a service in AWS Lambda for email processing.
The team encourages others to consider server-side Swift and points to recent improvements in Swift-Java interoperability, which may facilitate gradual adoption. Especially for Apple-oriented development, Swift offers an attractive solution because it simplifies the programming environment by using the same language everywhere, from device to cloud.
Risks and drawbacks
There are also risks. Cultured Code emphasizes that Swift’s server support is not yet as mature as other languages. For example, the lack of a suitable library was a reason to continue using Python 3 for e-mail processing. Another drawback is the long build time. This can be frustrating for developers testing code changes.