Nov 19, 20267 min read

Go vs Rust for Backend Services

How Go and Rust compare for APIs and workers: concurrency, latency and memory, compile times, ecosystem and hiring, with the same endpoint written in both.

Illustration for Go vs Rust for Backend Services

Go and Rust both compile to one native binary and handle thousands of concurrent requests, which puts them on the same shortlist for APIs and workers. Go gets there with goroutines and a garbage collector, while Rust has no collector and makes you prove memory safety to the compiler.

The trade shows up in build times, in how fast a new hire ships code and in tail latency for services with large heaps.

Go vs Rust at a glance

GoRust
ConcurrencyGoroutines and channels, built inasync/await on a runtime such as Tokio
Memory managementConcurrent garbage collectorOwnership and borrowing, no collector
Latency profileLow, with short GC pausesLow and predictable
Compile timeSeconds for most servicesTens of seconds to minutes for clean builds
Learning curveSmall language, productive in daysOwnership and lifetimes take weeks
Web frameworksnet/http, Gin, Echo, chi, FiberAxum, Actix Web, Rocket
Database accessdatabase/sql, pgx, sqlc, GORMSQLx, Diesel, SeaORM, tokio-postgres
Error handlingerror values, checked by conventionResult, checked by the compiler
Hiring poolLarge among backend engineersSmaller, growing

How does Go handle backend work?

Go

Go puts concurrency in the language: every incoming request in net/http already runs in its own goroutine, and starting more is a go statement or an errgroup when you want the first error to cancel the rest:

func loadDashboard(ctx context.Context, userID string) (*Dashboard, error) { g, ctx := errgroup.WithContext(ctx) var user User var orders []Order g.Go(func() (err error) { user, err = fetchUser(ctx, userID) return err }) g.Go(func() (err error) { orders, err = fetchOrders(ctx, userID) return err }) if err := g.Wait(); err != nil { return nil, err } return &Dashboard{User: user, Orders: orders}, nil }

Blocking calls are fine inside a goroutine, because the scheduler parks it and runs another, so database drivers and HTTP clients are ordinary synchronous functions. The standard library covers HTTP servers, JSON, TLS and crypto, and go build for a mid-sized service usually takes seconds, which keeps the edit and test loop short.

The garbage collector is the trade, since it runs concurrently with the program and pauses are short, as the GC guide explains, but a service with a very large live heap pays for scanning it in CPU and occasional latency spikes. GOMEMLIMIT and GOGC tune that trade rather than remove it.

Best fit: APIs, workers and internal services where team velocity and fast builds matter more than the last few milliseconds at p99.

How does Rust handle backend work?

Rust

Rust has no garbage collector, and the compiler tracks ownership of every value and frees memory when its owner goes out of scope, and the borrow checker rejects data races at compile time. Concurrency is async/await on a runtime, and Tokio is the default one for servers:

async fn load_dashboard(pool: &PgPool, user_id: &str) -> Result<Dashboard, AppError> { // Both queries run concurrently; the first error cancels the other. let (user, orders) = tokio::try_join!( fetch_user(pool, user_id), fetch_orders(pool, user_id), )?; Ok(Dashboard { user, orders }) }

Memory use and latency stay flat under load, and Discord's account of moving its Read States service from Go to Rust is the usual reference: the Go version showed latency spikes from garbage collection on a large in-memory cache, and the Rust version did not.

The cost is paid up front: lifetimes, Send bounds on futures and trait-heavy framework signatures slow down new Rust developers for weeks, a blocking call inside async code stalls a runtime thread unless it goes through spawn_blocking, and clean builds of a service with Axum, SQLx and serde take far longer than the Go equivalent. Rust has also ranked as the most admired language in Stack Overflow's developer survey for years, which helps hiring for people who want to write it but does not make the pool as large as Go's.

Best fit: services with strict tail-latency or memory targets, data-heavy pipelines, proxies and anything where a crash or race is expensive.

How do Go and Rust backends get their infrastructure?

Encore

Neither language decides where Postgres, queues and buckets come from, and the same lookup endpoint shows how that looks in each. In Go, Encore is a backend framework with built-in infrastructure: an endpoint and the database it reads are both declared in Go, encore run starts Postgres locally and applies the migrations, and a deploy provisions RDS or Cloud SQL in your own AWS or GCP account.

Application code passes through Encore and infrastructure guardrails to resources provisioned in your own AWS or GCP account.
Get started
brew install encoredev/tap/encore &&
encore app create
Copy

Run in your terminal to get started locally.

~
$ encore app create shop --example=hello-world$ cd shop && mkdir -p shop/migrations
// shop/shop.go package shop import ( "context" "errors" "encore.dev/beta/errs" "encore.dev/storage/sqldb" ) // Postgres locally under encore run, RDS or Cloud SQL after deploy. var db = sqldb.NewDatabase("shop", sqldb.DatabaseConfig{Migrations: "./migrations"}) type Order struct { ID int64 `json:"id"` Status string `json:"status"` TotalCents int64 `json:"total_cents"` } //encore:api public method=GET path=/orders/:id func GetOrder(ctx context.Context, id int64) (*Order, error) { var o Order err := db.QueryRow(ctx, `SELECT id, status, total_cents FROM orders WHERE id = $1`, id, ).Scan(&o.ID, &o.Status, &o.TotalCents) if errors.Is(err, sqldb.ErrNoRows) { return nil, &errs.Error{Code: errs.NotFound, Message: "order not found"} } if err != nil { return nil, err } return &o, nil }

In Rust, Encore works alongside the Axum app you already have. Encore for Rust is in private beta, and you can request an invite. The encore-dev crate declares the database as a static, Axum 0.8 keeps the routing, and encore::initialize() runs before the server starts:

// src/main.rs (Axum 0.8) use axum::{extract::Path, http::StatusCode, routing::get, Json, Router}; use encore::storage::postgres::Database; use serde::Serialize; static DB: Database = Database::new("shop").migrations("./migrations"); #[derive(Serialize)] struct Order { id: i64, status: String, total_cents: i64, } async fn get_order(Path(id): Path<i64>) -> Result<Json<Order>, (StatusCode, String)> { let row = DB .query_opt("SELECT id, status, total_cents FROM orders WHERE id = $1", &[&id]) .await .map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()))? .ok_or((StatusCode::NOT_FOUND, "order not found".to_string()))?; Ok(Json(Order { id: row.get("id"), status: row.get("status"), total_cents: row.get("total_cents"), })) } #[tokio::main] async fn main() { encore::initialize(); let app = Router::new().route("/orders/{id}", get(get_order)); let addr = std::env::var("ENCORE_LISTEN_ADDR").unwrap_or_else(|_| "0.0.0.0:8080".into()); let listener = tokio::net::TcpListener::bind(&addr).await.expect("bind"); axum::serve(listener, app) .with_graceful_shutdown(encore::shutdown::signal()) .await .expect("serve"); }

In both languages the migrations are plain SQL files that run locally and on deploy, Pub/Sub topics and buckets are declared the same way, and Encore provisions an IAM role for the service, or a service account on GCP. A team can also run a Go service and a Rust service in the same app when one hot path needs Rust, without a second way of managing infrastructure.

For coding agents the language matters less than the loop: with the database declared in the code, an agent can add a table and an endpoint in either language and test them against the local Postgres before the change reaches a cloud account.

Best fit: Go or Rust backends that want Postgres, Pub/Sub and buckets running locally and in their own AWS or GCP account from declarations in the code.

How to choose between Go and Rust

Pick Go for most API and worker services, especially when several people will work on the code, builds need to stay fast and the latency budget is in tens of milliseconds. Pick Rust when the service is latency-critical or memory-bound, holds large in-memory state, or sits in a path where a data race would be costly, and when the team is willing to spend the first weeks learning ownership. Many backends end up with both, Go for the bulk of the services and Rust for the one or two that need it.

Frequently asked questions

Is Rust faster than Go for backend APIs?

Yes, usually somewhat, and with lower and more predictable memory use since Rust has no garbage collector. For a typical API that spends most of its time waiting on Postgres or other services, the difference in request latency is small, and Go's faster builds and simpler code often matter more.

Should I use Go or Rust for a new backend?

Use Go when you want a team to be productive quickly on APIs, workers and internal services, with fast builds and a large standard library. Use Rust when tail latency, memory footprint or correctness under heavy concurrency are the main requirements, and the team is ready for a steeper learning curve.

Does Go's garbage collector cause latency problems?

No, not for typical APIs, since Go's collector is concurrent and pauses are short. It shows up in services that hold very large heaps or have strict tail-latency targets, which is the case Discord described when it moved its Read States service from Go to Rust.

Can I use Encore with both Go and Rust?

Yes. Encore is a backend framework with built-in infrastructure, and for Rust it works alongside Axum, currently in private beta. In both, Postgres databases and Pub/Sub topics are declared in code, run locally under encore run, and are provisioned in your own AWS or GCP account on deploy.

Deploy to your cloud on AWS and Google Cloud
without managing infrastructure

Encore lets developers and agents define application infrastructure directly in code, then automatically provisions it from local development to production in your AWS or GCP account.

~/orders — claude
Claude Code
Claude Code v2.1.180Opus 5.5~/orders