The main question: is swift mature enough to be used on the server side development?
Swift is a relatively new programming language, and it has been primarily used for developing iOS and macOS applications. However, it is also possible to use Swift for server-side development.
Swift has been gaining popularity as a server-side language in recent years, and many companies have started using it to build their server-side infrastructure. Swift is known for its performance, safety and its ability to handle high-concurrency environments.
Swift’s popularity in the server-side development is also due to its native support for modern features such as asynchronous programming, generics, and optionals, making it a great fit for building high-performance, scalable, and robust server-side applications.
At Wisk Swift does 3 things:
- provides a REST API through Vapor
- connects to the PostgreSQL database
- communicates with the other services through REST API calls
Unit testing/Integration testing
Swift has a great support for unit testing and integration testing. It is possible to write unit tests for the API and integration tests for the API and the database.
- Unit testing is done with the Vapor test framework
- It allows us to test the API using REST API or directly connecting to the database through Services
- Also we can do simple unit testing of the database models
What Swift does not do at Wisk
- Any time we need to use an external service we have a separate service that does that:
- Examples: Gmail, Couchbase, Firestore, Sendgrid, PDF, XLS generation and so on are implemented in either Kotlin or Php.
Challenges we faced over the years:
- for a long period of time the Swift concurrency model was not mature enough to be used in production, this changed in Swift 5.5 with the introduction of the async/await keywords
- the Swift ecosystem is still not as mature as the Java ecosystem, this means that there are less libraries available for Swift, for this we use services written in Kotlin
- production compilation time: we needed to create a swift build machine to cache previously compiled libraries, to avoid recompiling then every time we build the project
- we wrote our own method to serialize/deserialize to Dictionary and used SwiftyJSON
- this generated a lot of boilerplate code
- on the positive this allowed us to have a better control over the JSON encoding/decoding process
- swift has now a built in JSON encoder/decoder, we are still investigating if we can fully use it for our needs
Our experience with Swift
- It’s a great experience to work with Swift, it’s a very modern language, and it’s very easy to learn
- it’s fast and stable
- it allows us to write code that is easy to read and maintain
- it allows us easy refactoring of the code thanks to its static type system
Seed project
We have created a seed project where we add the new swift feature we use:
Please see it in action in module-swift
Services using Swift at Wisk
- Wisk API
- contains most of the business logic
- Wisk Queue
- it’s a wrapper around the PHP Queue Horizon
- Wisk POS Raw (this will be deprecated soon)
- it used to store the raw data from the POS for specific POS systems: touchbistro, silverware, etc
Moving forward we’ll continue to invest in the Swift Server Side for Wisk:
- Despite considering Kotlin for new services, we’ve observed significant advancements in Swift’s server-side maturity over the last year. Our confidence in Swift’s capabilities for server-side applications has substantially increased.
- Swift has demonstrated robust performance and a growing ecosystem, making it a viable and promising option for Wisk’s backend development.
- Moving forward, we’ll continue to invest in and commit to using Swift for server-side development.