Picture a service whose p50 sits comfortably under its deadline while p99 crosses it. Search ranking and recommendation serving both answer under a fixed deadline, and a late response there counts as no response. A common setup for such services handles requests in Go and hands model inference or large lookup tables to a Rust process in the same Pod.

That setup starts from a latency budget. Pulling pointer-heavy, long-lived data off the Go heap reduces garbage collection (GC) cost. Keeping the extracted computation in the same deployment unit avoids a network hop. A sidecar satisfies both.

Tail Latency

With a deadline, tail latency matters more than the mean. If p99 is over the deadline, one request in a hundred goes unanswered, and dashboards built on averages keep reporting a healthy service.

The usual sources of the tail are network round trips, lock contention, disk I/O, and GC. GC is where the language runtime has the most influence.

Go GC and Long-Lived Data

The Go GC runs most of its work concurrently with the application. Stop-the-World pauses occur briefly at the start and end of the mark phase, and the Go GC guide (written against Go 1.19) says they are designed not to scale with heap size. Long pauses are rarely the issue.

The cost lies in how much work the GC does. The guide models GC CPU cost as proportional to the live heap, with more pointers meaning more to visit. It lists these latency sources:

  • During mark, the GC targets 25% of CPU, which delays goroutine scheduling
  • Under a high allocation rate, the runtime makes request goroutines do GC work (mutator assist)
  • Pointer writes carry extra work during mark
  • Running goroutines pause briefly while their roots are scanned

The Go GC has no generations. Keep pointer-heavy, long-lived data on the heap, such as string-keyed maps, feature tables linked by pointers, or caches shaped like object graphs, and every cycle traverses it again. A large pointer-free array has nothing to scan and costs little. Model weights are mostly pointer-free tensors, so they barely register with the GC either; inference moves to a sidecar for its engine ecosystem and fault isolation, not for GC. Request-handling code allocates objects that die young; mix pointer-heavy long-lived data into the same heap, and request handling shares the traversal cost.

Diagnosing GC

Confirm GC is the cause before changing the architecture. GODEBUG=gctrace=1 prints the duration and heap size of each cycle. runtime/metrics exposes the pause distribution and the share of CPU spent on GC. Check whether p99 spikes line up with GC cycles and whether the GC’s CPU share is high.

If GC is the cause, tune first. Raising GOGC trades memory for fewer cycles, and GOMEMLIMIT sets a memory ceiling alongside it. Reshaping data into pointer-free layouts also helps, as does placing it off the Go heap with mmap, at the cost of serialization and losing native pointer structures. For small data, that ends it. What tuning can’t remove is the per-cycle traversal of pointer-heavy long-lived data that stays on the heap. Removing that requires a different heap.

Setup Options

SetupGainsCosts
All GoSimple to deploy, debug, and hire forLong-lived data stays on the Go heap and carries GC cost
All RustNo GCI/O and orchestration code also move to Rust, slowing development
Rust or C++ library via cgoData lives on the C heap, invisible to the Go GCEvery call pays cgo overhead, and a library crash takes down the Go process
Computation as a separate serviceSeparate heap, independent scalingA network round trip on every request
Computation as a separate process in the same PodSeparate heap, no network, process-level fault isolationInter-process communication cost and deployment complexity

cgo solves the GC problem at the expense of fault isolation. A single memory error in the inference engine kills the process serving requests.

A separate service keeps its data in its own process, so the data doesn’t move. What moves is every request, and the GC tail becomes a network tail. A remote cache is worse: the data itself crosses the network, someone has to keep the cache fresh, and at hundreds of megabytes it can’t be fetched per request.

A separate process in the same Pod gets its own heap without touching the network.

Setup OptionsPodHTTPUDSUDSGo servicerequest handling, I/ORust sidecarmodel inferenceRust sidecarlookup tablesClient

Containers in a Pod share a network namespace and volumes. The two processes could talk over localhost TCP, but a Unix Domain Socket (UDS) on a shared volume skips the TCP/IP stack as well and keeps the exchange inside one kernel. The millisecond-scale network round trip is replaced by a smaller inter-process cost.

The Rust process has no GC. Ownership fixes most deallocation points at compile time, and reference counting through Arc touches only the objects it manages. Nothing walks the whole heap at runtime. What the sidecar buys is predictable latency more than raw speed.

Compute Sidecars

Say sidecar and most people think of a proxy like Envoy. A service mesh sidecar intercepts application traffic and applies mTLS, retries, and routing; the application never has to know it’s there.

A compute sidecar is called explicitly by the application and runs part of the domain logic. Without it, requests can’t be served.

AspectProxy sidecarCompute sidecar
InvocationIntercepts traffic transparentlyCalled directly by the application
ResponsibilityNetwork policy (mTLS, retries, observability)Domain computation (inference, lookup, aggregation)
Application dependencyNoneRequired to serve requests

Microservices split along domains and teams. A compute sidecar splits a single-domain service into processes along runtime characteristics: Go takes I/O and orchestration, Rust takes large state and numeric work. One service, several processes.

Kubernetes native sidecars, on by default since reaching Beta in 1.29, express this in the Pod spec. Per the official docs, a container under initContainers with restartPolicy: Always becomes a sidecar that runs for the life of the Pod. As an init container it starts before the main container, and on termination the kubelet waits for the main container to stop before shutting the sidecar down. Plain containers declared side by side get no such ordering. The feature went Stable in 1.33.

Costs of the Sidecar Setup

The setup gives up independent deployment and scaling to win latency. Here is what that costs:

  • No independent scaling: when only the sidecar is busy, the whole Pod scales, idle Go capacity included
  • Duplicated state: each replica loads its own copy of the sidecar’s data, so memory grows with the replica count
  • Coupled startup and lifetime: if a sidecar fails to start, the main container never starts
  • Harder tracing: traffic between the processes never hits the network, so no network trace exists. Every message needs a request ID to tell which request slowed down where
  • Two languages to operate: someone on the team has to read Rust when it breaks

Startup order and traffic are separate concerns. A native sidecar only delays the main container’s start; readiness decides when the Pod receives traffic. If readiness passes before the sidecar’s first data load, the Pod takes traffic while sidecar calls fail. Readiness should require that first load.

When to Split Sidecars

A new computation can go into an existing sidecar or a new one. Extending an existing sidecar reuses its communication path and deployment config, so the change stays small. A new sidecar needs its own container definition, deployment config, call path, and monitoring.

The main gain from a new sidecar is fault isolation: one computation crashing or stalling leaves the other alone, with separate restarts and resource limits. So ask whether the two computations can fail together. Recording call failure rates and latency per computation turns that question into a measurement.

Adoption Criteria

A sidecar fits when:

  • Diagnosis confirmed GC as the cause, and tuning can’t meet the latency budget
  • It’s called several times per request against a millisecond budget
  • It scales the same way as the main service

A separate service fits when:

  • Only the computation needs to scale independently
  • Several consumers share the same large state
  • Calls are rare or can be asynchronous

With a generous budget or small data, you need neither. One language in one process, tuned, is cheaper to run.

Wrap-up

The case for a Rust sidecar rests on two findings: a deadline that turns tail latency into the problem, and a diagnosis that traces the tail to long-lived data on the Go heap. A process in the same Pod puts that data on another heap and keeps communication off the network, at the price of independent scaling and separate lifetimes. Use the sidecar only when that exchange pays off inside the latency budget.

References