ADR-00012 — Rust vs Go: Security-Critical Services
- Status: Approved / Implemented
- Date: 2026-09-27
- Authors: Engineering Team
Context
pii-service, pci-service, media-access-service, payment-service, document-service, provider-auth-service, user-secure-engine, and notification-service each either hold decrypted PII/PCI plaintext in memory (even briefly, inside service::encrypt’s get_attributes call) or verify a signing key/token on the gateway hot path. Every one of them is built in Rust, not Go — even though Go is this platform’s default backend runtime per ADR-00011. This ADR states why, traceable to SR-007’s FR-02.
Decision Drivers
- Deterministic reclamation of memory holding secret material. BRD-007’s BR-03 requires the smallest achievable risk that decrypted PII/PCI plaintext lingers in memory longer than necessary.
- Compile-time elimination of memory-safety bug classes, not just runtime mitigation of them — reduces the attack surface a vulnerability scan or an incident review has to consider in the first place.
- Consistency with the rest of the platform’s tooling where it doesn’t compromise the above — Rust’s own core lib (
rust-lang-core-lib) already mirrorsgo-lang-core-lib’s capability shape (errors, logging, auth, tracing), so this isn’t an isolated, unsupported choice.
Options Evaluated
Option 1 — Rust (CHOSEN)
- Rust’s ownership model means a value holding decrypted secret material is deterministically dropped — and its memory reclaimed — the instant it goes out of scope, with no dependency on a garbage collector’s schedule. This is a precise, verifiable property of when reclamation happens, not a vague “Rust is safer” claim.
- No garbage collector also means no compaction/copying pass that could leave a stale, still-readable copy of previously-decrypted data in a heap region the collector hasn’t yet overwritten — a risk that exists in principle with any moving/compacting GC design.
- The borrow checker rejects use-after-free and data-race bugs at compile time, rather than relying on a fuzzer, a sanitizer, or production monitoring to catch them at runtime — this removes an entire bug class from the services most worth removing it from.
- This is the same ownership-boundary reasoning already documented for the shared
pii-service/pci-serviceEAV implementation in the platform’s layered architecture standard — this ADR generalizes it to the full list of Rust services, not just the two encryption stores. - Cons & Accepted Trade-offs:
- A steeper learning curve than Go for new contributors — accepted because this is a deliberately smaller set of services (8 of 17 backend services) carrying the platform’s highest-sensitivity workloads, not the default.
rust-lang-core-libhas some genuine gaps againstgo-lang-core-lib(no shared bootstrap equivalent to Fx, gRPC status reporting is coarseok/error— see the platform’s cross-cutting principles) — accepted because none of these gaps touch the memory-safety property this decision is actually about.
Option 2 — Go
- Pros: One backend language instead of two; every engineer already comfortable with Go’s tooling and
go-lang-core-libconventions could contribute to these services without context-switching. - Cons (Why Rejected):
- Go’s garbage collector reclaims memory on its own schedule, not deterministically tied to a value going out of scope — there is no language-level guarantee about when a buffer that held decrypted PII/PCI plaintext is actually overwritten or unmapped, only that it eventually will be.
- Go has no borrow-checker-equivalent compile-time check for use-after-free or data-race conditions — those bug classes are caught (if at all) by the race detector at test time or by a runtime panic, not ruled out structurally.
- This is precisely the risk BRD-007’s BR-03 asks to be minimized for exactly this category of service — using Go here would apply the platform’s general-purpose default to the one category of workload it was least designed to protect.
Final Decision
Option 1 (Rust) is selected for every service whose core responsibility is handling decrypted PII/PCI plaintext or verifying a signing key/token on the gateway hot path. The deciding factor is deterministic, ownership-based memory reclamation plus compile-time elimination of use-after-free/data-race bug classes — a property Go’s garbage-collected runtime cannot offer at the language level, regardless of how carefully application code is written on top of it.