Backend Languages
Status
Candidate - Under consideration for approval
Owner
[To be assigned]
Description
This page sets the default backend language for GitLab services and how existing code moves between languages. It applies to services, libraries, and performance-critical components that ship to GitLab.com, Dedicated, and Self-Managed.
Rust is the first choice for new backend code, and Go is the second. Go is fully supported. Ruby and Python stay supported where they already run, but are discouraged for new work. Choosing anything other than Rust for new work needs a documented reason in the design document or decision record.
| Language | Position | Use for |
|---|---|---|
| Rust | First choice | New services, new libraries, and rewrites of performance-critical code |
| Go | Second choice, fully supported | Existing Go services, their extensions, and new work where Rust does not meet the need |
| Ruby | Discouraged, monolith only | Existing product code inside the Rails monolith |
| Python | Discouraged, case-by-case | Services that depend on the Python ecosystem, such as AI and ML |
Why This Should Be a Key Abstraction
- Predictable performance: Backend code should keep latency and memory use predictable under load, and use little CPU and memory for the traffic it serves, whether the workload is CPU-bound or I/O-bound. This matters for services that run in every cell and on every Self-Managed instance. Backpressure, connection pooling, and timeouts matter in any language, but a garbage collector adds pauses and memory overhead that grow with the live heap and the allocation rate. Caches, proxies, and services that hold many connections hit this even when they are I/O-bound. Rust has no garbage collector and frees memory as soon as it is no longer used. See the examples from production.
- Incremental rewrites: Existing applications should move to a new language piece by piece, not in one big rewrite. Rust has no runtime of its own, so a native extension in Ruby or Python can be swapped for Rust first, and the rest of the application switched separately.
- Correctness over time: Code should stay correct as it changes hands, because components outlive the teams that wrote them. The Rust compiler catches memory, concurrency, and type errors that otherwise surface in production. This matters more as AI agents write a growing share of code: the compiler is a deterministic guardrail for generated code, and the type system can make invalid states unrepresentable, so mistakes fail at build time instead of at runtime.
- One default: Teams should not re-litigate language choice per project, and tooling, such as LabKit, CI templates, and security tooling, should focus on fewer runtimes. One first choice and one second choice keep that set small.
- Platform support: New services should get logging, metrics, tracing,
and deployment from the platform.
Theseus supports Go and Rust,
LabBench scaffolds and
builds both runtimes, and
labkit-rsis wire-compatible with LabKit Go, so Rust and Go services share dashboards and traces. Go has the more complete support today. The long-term plan bringslabkit-rsto feature parity, and Rust support grows as more services are built in Rust.
Why Rust and Not Go
Go is a valid choice, and for many services it works well. This page sets the long-term direction. When both languages meet the need, choose the one with better and more predictable performance, and the one that mixes with the code we already have. That is Rust.
The usual case for Go is networking and I/O-bound work. Predictable latency
and memory matter for that work too, and Rust’s async ecosystem, built on
Tokio, is proven for it. Go stays the fully supported
second choice for existing Go services, and for new work where Rust does not
meet the need. A missing labkit-rs feature does not count, see the
long-term plan.
Examples from production:
- Discord, Read States service: Go’s garbage collector scanned a large in-memory cache and caused latency spikes every two minutes. The Rust rewrite removed the spikes.
- Grab, Counter Service: the Rust rewrite used about 4.5 cores where Go used 20 at the same load, with similar p99 latency, for about 70% infrastructure savings.
- Cloudflare, Pingora: a Rust HTTP proxy that replaced NGINX and uses about 70% less CPU and 67% less memory for the same traffic.
Use Cases
Rust
Use Rust for:
- New services and modular features built on Theseus
- New shared libraries, including LabKit-level components
- Hot paths extracted from the monolith, as a Ruby native extension or as a separate service
- Components with strict latency, memory, or safety requirements, such as parsers, routers, proxies, and data pipelines
- Any other new backend code that the Go, Ruby, and Python sections below do not cover
Go
Go remains fully supported: LabKit Go, the Go service template, CI tooling, and the Go guidelines stay maintained. Go is the second choice for new work. Use Go for:
- Existing Go services such as Gitaly, Workhorse, GitLab Runner, GitLab Shell, GitLab Pages, the Container Registry, and the GitLab Agent for Kubernetes
- New components inside an existing Go codebase
- Kubernetes operators and controllers, where the Go ecosystem is the standard, with a documented reason
- New work where Rust does not meet the need, with a documented reason. A
missing
labkit-rsfeature does not count, see the long-term plan
There is no plan to rewrite working Go services in Rust. Do it only when a component has a measured performance or reliability problem that Go cannot address.
Ruby
Ruby remains the language of the Rails monolith, but is discouraged for new code that can live outside it. Use Ruby only for:
- Product features, APIs, and background jobs inside the monolith
- Gems that are used only by the monolith
Rewrite Ruby code in Rust where it matters for performance or longevity:
- Performance: CPU-bound or memory-heavy code with a measured cost, such as parsing, rendering, serialization, diffing, and scanning
- Longevity: Code that is being extracted from the monolith into a modular service, or a platform component expected to live for years
Do not rewrite Ruby code that is neither a measured bottleneck nor a candidate for extraction.
Python
Python is discouraged and accepted case-by-case. Rust is the preferred choice, and Python needs a documented reason in the design document or decision record, such as:
- A dependency on Python-only libraries, such as AI and ML frameworks
- Extending an existing Python service, such as the AI Gateway or the Duo Workflow Service
Follow the Python guidelines. Theseus does not support Python services yet, so a Python service takes on its own build, deployment, and observability work.
Do Not Use For
- Rust: Do not start a Rust component inside an existing Go service; keep one language per service unless the boundary is a library or process
- Go: Do not choose Go for a new standalone service where Rust meets the need
- Ruby: Do not build new services outside the monolith in Ruby
- Python: Do not choose Python where Rust meets the need
- Other languages: Do not introduce a new backend language without Architecture Board approval. Start the discussion in #principal_plus_engineers
Long-Term Plan
- LabKit parity: Bring
labkit-rsto feature parity with LabKit Go, so a Rust service gets the same logging, metrics, tracing, and platform integration as a Go service. A missing feature inlabkit-rsis not a reason to choose Go: close it inlabkit-rsinstead, solabkit-rsmatures with every new service. - Rust in the monolith: Rewrite measured hot paths of the Rails monolith
in Rust. Track 4 of the GitLab Rails Decomposition
tracks the candidates, such as:
- Markdown rendering, which already runs on Rust through
gitlab-glfm-markdown - Diff and job log processing, which are CPU-bound and memory-heavy
- Sidekiq workloads limited by the Ruby global VM lock, where Rust’s concurrency removes the bottleneck
- Markdown rendering, which already runs on Rust through
- Rust on Theseus: Keep the Rust runtime in Theseus and LabBench on par with Go, including service templates, CI templates, and security tooling.
Integration Guidance
For New Services
- Default to Rust: Scaffold with
bench assembly create --runtime rustor start fromrust-service-template - Use LabKit: Use
labkit-rsfor logging, metrics, and tracing - Choosing another language: Record why Rust does not meet the need in the design document or decision record
- Ship everywhere: Follow the Theseus core contract so the same artifact runs on GitLab.com, Dedicated, and Self-Managed
For Rewriting Ruby in Rust
- Measure first: Show the cost with production data before rewriting
- Pick the boundary:
- In-process hot path: a Rust native extension built with
rb_sys, following theprometheus-client-mmappattern - Extracted domain: a Rust service on Theseus
- In-process hot path: a Rust native extension built with
- Keep behavior identical: Run the existing Ruby specs against the Rust implementation and roll out behind a feature flag
Related Key Abstractions
- gRPC, REST - Communication protocols between services in any language
- OpenTelemetry - Tracing configured through LabKit in every language
- Sidekiq - Background processing inside the monolith
Support and Resources
- Theseus documentation and LabKit
labkit-rsandrust-service-templatebenchCLI- Go standards and style guidelines
- Ruby style guide
- Python guidelines
fc3c4b54)
