Go

The web server of Cool Maze - Push to Computer is written in Go.

As explained in the article Cloud architecture, the backend consists of several components. The app logic is handled by the Cloud Run app. Its role is to enable the mobile app to upload resources, let the web app download resources, and store anonymous usage data for analytics.

The programming language used for the server app is an implementation detail. Several options would have worked: Java, Node.js, Python, C#, etc. They come with slightly different paradigms, trade-offs and performance characteristics.

Go is a popular choice for web services. It has excellent support for common needs in an HTTP server: networking, JSON, concurrency, as well as client libraries for all the Google Cloud products.

Performance

Go is a compiled, statically typed, high-performance language.

Memory

Go software tends to be frugal in memory usage. A Go server typically uses only a few MB of memory, making it a good fit for small virtual machines or containers.

The memory is safe: we don’t risk buffer overflows leaking other users’ connection details. The garbage collector automatically takes care of freeing memory when appropriate.

Concurrency

Each user request is processed in its own goroutine, which is like a lightweight thread. Many requests can be processed concurrently, instead of sequentially.

A single request may also use concurrency for its own purpose. For example, sharing 5 photos involves generating 5 pairs of upload/download signed URLs. Each pair is generated in its own goroutine.

Concurrency helps achieve low latency, which improves the user experience.

Scalability

A single instance of the server supports hundreds of simultaneous users.

When the traffic increases, Cloud Run automatically starts new instances. This works well because each server instance is stateless, so an incoming request can be processed by any of the instances.

Fast startup

During autoscaling, a request may have to wait for a new instance to start. This process typically takes just 200 ms for the full container to load and the Go server to become ready.