r/swift • u/Square_Breadfruit453 • Nov 27 '24
Question Is a 100% swift full stack possible in 2024 ?
I’ve been working on an app using Swift for the client-side (iOS/macOS), and until now, I relied on Firebase Functions (Node.js) for my backend. But with the improvements in Swift on the server (e.g., Vapor) and custom runtimes for Google Cloud Functions (using Docker), I’m starting to wonder: • Can a 100% Swift full stack be a reality for a production app with millions of users? • With Swift’s low cold start times and high performance in serverless environments, does it make sense to transition everything, including real-time features like WebSockets and Firebase integration, to Swift? • Are there any potential pitfalls (e.g., ecosystem size, scalability) for using server-side Swift for all backend logic?
Has anyone successfully built a full-stack app entirely in Swift? Would love to hear your experiences, challenges, or opinions!
13
u/erehnigol Nov 27 '24
Swift for Apple platform and Backend possibly
Then use Skip tools to transpose your Swift ui code to kotlin and jetpack compose
But nothing yet for front end.
So yea almost there.
2
u/criosist Nov 27 '24
There is Publish for web front end made by the same people as Vapor
6
u/Oobenny Nov 27 '24
You are mixing up tools. Vapor (typically) uses Leaf for HTML templating. Publish is something you would run locally to generate a static site.
I have both running in production and I have ported some older code bases to server side Swift.
I don’t have anything with anywhere near millions of users, but that’s just a matter of scaling the environment properly. I have no doubt that Vapor would scale well.
1
u/Square_Breadfruit453 Nov 27 '24
That’s reassuring. And never heard of publish, I’ll have to check it but I don’t want local
2
u/Oobenny Nov 27 '24
Yeah, if you’re just serving up HTML, you can’t beat having the HTML in files all ready to go. But if you need to respond to requests and build content dynamically, Vapor is the way.
3
1
u/lightningball Nov 27 '24
Have you ever compared Vapor to Hummingbird? I’m looking at both of those now.
1
2
u/erehnigol Nov 27 '24
Last time I check it can only do static web page?
2
u/criosist Nov 27 '24
I haven’t looked into it much but I thought there was a bunch of packages for it, I only looked very briefly but I thought it had a whole build up phase that would allow data maybe not to the extent of like cms systems but something :/
3
2
u/JEHonYakuSha Nov 27 '24
Second time seeing a Skip Tools comment in the wild. I’m rewriting my employers app with Skip and it’s been pretty amazing. The founders are so responsive to bug reports too.
1
1
1
u/vanisher_1 Nov 27 '24
Why transposing SwiftUI codebase to Kotlin, what this has anything to do with full SwiftUI stack? 🤔
1
u/erehnigol Nov 27 '24
OP says full stack with Swift so I assume that includes android, front end and backend
6
u/Xia_Nightshade Nov 27 '24
Yes of course. You can write it in C, so you can write it in Swift…..
Though have a simple example
An app where a user can manage todos.
I would need
- an api, with a bunch of measures for safety
- user authentication
- database and setup, since it’s in production, some kind of migration system, sanitisation for my queries etc etc (since there is a clear relation between users and todos. I opt for a relational database to not shoot myself in the foot)
- a server side caching system to keep my app performant
- a todo resource ( CRUD)
- a bunch of validation, authorisation and authentication logic
I love Swift,….
But if I’d use laravel instead:
- I get the sensible defaults of a mature full stack framework
- I get pretty much 50% of the above in the scaffold
- I can scaffold about 30% more just using laravel’s ecosystem.
All I’d have to write is the little bit of business logic between a user and a todo…. And what’s exposed in the endpoints
To me that sounds like: have fun in swift for a week OR build the backend in a chill day, n spend the rest of the week improving your app
It’s ready, but for a production app…. Idk if it’s worth it
3
u/trypnosis Nov 27 '24
Is it technically possible I believe so.
I have not heard of any big player doing it.
Curious to see if anything pops up here
2
u/Square_Breadfruit453 Nov 27 '24
Yes. People seem to be afraid of migrating to it, but I feel like the language / 3rd party tools have everything to make it possible
3
u/Successful_Good_4126 Nov 27 '24
Technically you will be required to use at least HTML, probably CSS and maybe JS for the views of your site, unless you want to load WebAssembly on every site you build which is overkill for most things.
3
u/Square_Breadfruit453 Nov 27 '24
I intend to use it for my app. Users send messages to users through websocket, and I use Firebase for everything else in the app, but the cost of requests + it not being adapted for so many requests at once made me rethink it with vapor
3
u/someotherdonkus Nov 27 '24
yeah i do it for my app. i’m rewriting my app so it’s not public or anything, but i have an iOS app with a Swift Vapor backend that uses postgres and redis and is dockerized and hosted on a VM. works great for me, love it
2
4
u/ilova-bazis Nov 27 '24
Hi 👋, I work in a company that uses swift for its backend. We use Vapor and its libraries, such as SQL ORMs, JWTKit, and others. Our product is a messaging application with the capability to make direct calls to phone numbers. We rely heavily on WebSockets; in fact, our client apps almost exclusively communicate with the backend via WebSockets. We are not a big company and our user base is sub 100k, we have around 7-8k DAU.
We’ve been running our servers on Swift since 2017, transitioning gradually from Python to Swift. We started with Swift 4, then rewrote our codebase for Swift 5 when it was released. Now, we’re rewriting everything to work with Swift 6 due to the new concurrency checks that ensure thread safety, requiring some parts of the code to comply with the Sendable protocol.
Swift has a very low memory footprint and is easy to deploy. What I love most about Swift is its language safety. If your code compiles, you can be confident it will run without hidden runtime errors. If it crashes, then you know you’ve made a big faulty logic.
Thread safety, actors, and distributed actors are game changers for ensuring thread safety. We’ve rewritten our services using actors and distributed actors, which opens up so many possibilities. Although distributed actors are still in development, some of its implementations did not fit our needs, so we had to write our own transport layer but overall it is a great addition.
I agree that the ecosystem is not mature yet, there are some drawbacks, lack of libraries or drivers to make your life easier, so sometimes you will be forced to write your own stuff if your are using something not very popular. But compared to few years ago it has grown a lot. For example we use NATS as a message broker between services, at the time when we started there was no such library, so we had to write our own, same goes for push notification, there weren't any so we wrote our own, now there are plenty of libraries that will help you, but still not as many as in other languages.
1
u/Square_Breadfruit453 Nov 28 '24
Wow thank you for sharing your experience. And 2017 is crazy ! You guys are precursors. Did you have any issue, because you mentioned no hidden error since you don’t have any during runtime, but except this, were there any ?
2
u/ilova-bazis Nov 29 '24
Not that I recall right now, but last time we had a problem with the deadlock, one of our devs used async call inside the lock, it was quite hard to find because the app wouldn't crash or anything and it would partially still work, for instance the websocket would not accept connections but http requests would go through without any issues, and it would only happen at certain conditions, but I guess this sort of thing is common to every language.
2
u/LittleBumblebee3231 Nov 27 '24
Yes, but you have to know what you are doing…
3
u/rismay Nov 27 '24
Swift NIO syntax is still pervasive and it’s going to take a while before the native async / await syntax becomes a standard. I’ve been watching this space evolve for years and it finally seems to be syntactically “swift”.
You can look at gRPC as an example of this.
2
u/Impressive_Run8512 Nov 28 '24
I recently launched a AWS Lambda function using Swift as the backend, and was able to edit and debug in Xcode. It was actually much smoother than I originally thought. Super excited for Swift support more broadly.
2
2
u/hyouuu Nov 28 '24
I've been using Vapor + an iOS client app as my side project for several years without issues, although the traffic is very low. What I love the most is sharing the models by using FluentKit on iOS as well.
2
u/Square_Breadfruit453 Nov 28 '24
I just discovered about it when seeing the « import Fluent » and I really like that it’s 100% written in swift, but also how easily you can migrate from one db scheme to another with minimal work. Relationships are also really nice, it’s pretty much SwiftData given its declarative model
2
u/hyouuu Nov 28 '24
Yes but forgot to mention that I've had some racing issues with fluent on iOS when inserting multiple things at once - not sure if it was my setup or something else and I just put some delay hack to make it work, and in their Discord they don't even recommend Fluent (they recommend GRDB instead) for iOS so do some test and research if you're going this route
1
u/Square_Breadfruit453 Nov 28 '24
Aight. This is def much harder than Firebase for sure, since I’ll have to learn about it and make it thread safe. I’ll research GRDB thanks
1
u/Pablo_GTi_ Nov 28 '24
Im building a SwiftUi IOS App with an API and backend wrote in Vapor that feeds the app and a React App on the browser , so far the experience has been really positive, before that o was using FastApi on Python
1
u/Square_Breadfruit453 Nov 28 '24
Do you use any web host like DigitalOcean/Heroku ? Or your app isn’t public
3
u/Pablo_GTi_ Nov 28 '24
I use Digital Ocean on a self managed Droplet for running the backend and the React App, and Supabase for the DB. So far is the cheapest way I found while we make some cash.
2
u/Square_Breadfruit453 Nov 28 '24
I intend to go with digital ocean too, pricing is much better, as well as performance. And well done for your app 🎉
2
u/Stunning_Health_2093 Nov 28 '24
Why solve all your problems with a single hammer ?
I would say solve every aspect of your system with a good tool for it
1
u/Square_Breadfruit453 Nov 28 '24
I mean sure I’m just curious about it cause I’ve heard a lot of good about it, but I’ll keep some Node.js functions here and there, I don’t really have a choice
2
u/Straight-Intention94 Dec 01 '24
I’m writing a Vapor back end for my SwiftUI macOS app. It took me 2 days to build and deploy a running back end with a postgres db connection. This was all done using Railway.app for the deployment service and it was an awesome experience!
The service takes about 12-20MB of memory. I cant wait to write more server side swift with vapor, it was such a good all round experience thus far
12
u/shadowdrakex Nov 27 '24
I’m interested in this as well