1

I need to implement the following functionality.

  1. Client side: iOS (and Android) App calling a web service
  2. Server side: Web service on Goolge Cloud.

The server side should have HTTP/2, TLS 1.3

IBM Kitura makes very easy to generate the client code for Android and iOS to talk to SwiftNIO server.

The Kitura macOS App is really powerful and easy way to create the service definition and generate the client and the server code. The Kitura server is SwiftNIO 2.0 server which is working nicely with latest Apple iOS.

I explored the possibility to run the server code on IBM Cloud. IBM Swift Cloud Functions are very lightweight. But there are two big issues with it.

1) Using custom domain with LetsEncryt - SSL certificate is not updated automatically. 
Which means every 90 days it must be updated manually. 
Basically - no managed SSL.

2) only ipv4, no ipv6 support with means it cannot pass the 
Apple App Store requirements. 

So these two issues rule out IBM Cloud.

With Google Cloud these two are not issues.

Now I'm exploring the options to build the RESTful API with one of these:

1) Swift
2) Golang

Option 1) is a good one because of The Kitura macOS App. I can develop with just one language Swift which would speed up the development time. There is a downside - no support for Swift client libraries for Google Cloud API.

So the SwiftNIO based API can be used as a front end and Google Golang Cloud Functions should be called from 1).

Or if I use ColdRun it is possible to call Golang from Swift as it is possible to use Gomobile from iOS. How?

Also Kitura can generate OpenAPI interfaces.

Option 2) - to use Golang exclusively. Downside - I cannot use the Kitura Swift functionality.

What are the options on the Google Cloud server:

1) Google Cloud Run (with container for Swift)
2) Google Cloud Functions for Golang
3) Google Appengine for Golang

Options: 1) I don't have answers about Cold Start and the other parameters as 2) and 3)

2) is very good and inexpensive one: 2 million invocations per month (includes both background and HTTP invocations) 400,000 GB-seconds memory, 
200,000 GHz-seconds of compute time 5 GB network egress per month Max function duration = 9 mins Cold Start = .5-1.5 Seconds

3) Cold Start = seconds but I suppose 2) is the best one on this parameter.

I suppose ipv4 and ipv6 and Apple App Transport Security (ATS) requirements are fine with 1), 2) and 3) but I need a confirmation.

I don't have answers about what needs to be done about HTTP/2, TLS 1.3 on 1), 2) and 3).

One more thing. I need to be able to call BigQuery. For now the only supported ready to use client library is for Golang.

So I suppose SwiftNIO on Cloud Run + Golang CloudFunction should be the best possibility.

ahmet alp balkan
  • 42,679
  • 38
  • 138
  • 214
thstart
  • 397
  • 3
  • 15

1 Answers1

3

Cloud Run doesn't support streaming HTTP/2. It should have up to date ciphers.

I have run Swift on Cloud Run (here's an example using Protobufs and client/server swift). It uses Kitura.

Run will likely be cheaper than GCF and GAE, due to concurrency and no billing cliff. Cold start performance will likely be similar across Go and Swift because they're both launching binaries, but I admit I have't

ATS shouldn't be an issue since Run does SSL for you (and .app domains are pretty neat in that I believe they require SSL and HSTS).

Mike McDonald
  • 15,609
  • 2
  • 46
  • 49
  • I have an .app domain - what advantage they have? – thstart Jun 18 '19 at 23:24
  • Looked at your example - would explore it - looks nice. – thstart Jun 18 '19 at 23:26
  • Up to now - I'm using Golang exclusively. Integrated Gomobile with iOS successfully. Looking for a way to integrate Golang with server side Swift. So if I have to call BigQuery from Swift I can use the Golang BigQuery client library directly without a need to use separate service. Why on earth Google didn't made Swift client libraries for Google Cloud APIs? – thstart Jun 18 '19 at 23:29
  • I like CloudRun- very powerful and flexible - but better get some info on Cold Start stats from the devs. If this should be my mobile facing backend - Cold Start is very important. May be warm instances? – thstart Jun 18 '19 at 23:33
  • Does SwiftNIO require HTTP/2 streaming? I'm trying to tell if it's relevant. The OP says they are running a REST API, so I don't think it's streaming. – ahmet alp balkan Jun 19 '19 at 20:34
  • No, I don't think SwiftNIO requires streaming. GCP has 7 supported languages, and unfortunately Swift isn't one of them, though it's something we're considering as it gains popularity. We have considered a `minInstances` setting on Cloud Run to keep instances warm, but it would necessitate changes in the billing model (since you're keeping instances around). Depends heavily on the use cases. – Mike McDonald Jun 20 '19 at 00:07
  • SwiftNIO does not requires HTTP/2 but supports it: https://github.com/apple/swift-nio HTTP/2 and TLS 1.3 would make the interface much faster if it is possible. Also there is no Swift implementation of Goolge Cloud client libraries so I have to use a separate App Engine server for that purpose. – thstart Jun 20 '19 at 23:44
  • Or for for OpenAPI it is better to use: https://cloud.google.com/endpoints/ Does CloudRun provide same front end functionality - An NGINX-based proxy and distributed architecture? This documentation explains Endpoints for Cloud Run: https://cloud.google.com/endpoints/docs/openapi/get-started-cloud-run – thstart Jun 21 '19 at 00:44
  • You don't have to use a separate App Engine app, you can always use the REST or RPC clients directly. If you don't want to do that, than just write the Run app in Go and use the client library. – Mike McDonald Jun 22 '19 at 23:09
  • The Endpoints quickstart describes running the proxy on Cloud Run, in front of another Cloud Run instance (though the backend can be anything: a GAE app, Cloud Functions, a GCE VM, etc.). It adds some additional latency, but the proxy does several other things (e.g. API key validation, rate limiting, etc.) that you won't get with Kitura and OpenAPI. – Mike McDonald Jun 22 '19 at 23:10
  • <"Run will likely be cheaper than GCF and GAE, due to concurrency and no billing cliff. "> So basically the frontend - Service #1) SwiftNIO, there is not Swift library for BigQuery, so I should use Go for that. Go lib inside server side Swift not possible so I have to use separate Service #2) in Go. I use Google AppEngine Go. So you say if I need Go better use CloudRun? – thstart Jun 26 '19 at 20:25
  • This is the Docker file generated from Kitura Desktop App: https://github.com/topinvestor/kitura/blob/master/Dockerfile Deploying to Google Cloud Run get the following errors: https://github.com/topinvestor/kitura/blob/master/README.md Deployment failed ERROR: (gcloud.beta.run.deploy) Cloud Run error: Container failed to start. Failed to start and then listen on the port defined by the PORT environment variable. Logs for this revision might contain more information. – thstart Jun 27 '19 at 00:48
  • I have a simpler `Dockerfile` from the above link: https://github.com/mcdonamp/running-swift/blob/master/backend/Dockerfile – Mike McDonald Jun 27 '19 at 21:36
  • It seems to me like if you feel the need to use Go for client library support, just write the whole thing in Go rather than write a Swift front end that calls a Go backend. Or use Swift and the REST APIs for GCP. – Mike McDonald Jun 27 '19 at 21:37
  • Or if possible - to use Gomobile framework in Server Side Swift project? I don't know if it is possible. – thstart Jun 28 '19 at 21:31
  • I guess I don't understand why you feel the need to use both Go and Swift. Either will get the job done, and it feels unnecessary to use both. – Mike McDonald Jun 30 '19 at 15:14