Backend Development 15 min read

How Merge Compilation Supercharges ByteDance’s Microservices: Performance Gains and Technical Challenges

This article explains ByteDance’s merge‑compilation technique that combines multiple microservices into a single binary at build time, detailing its performance benefits, architectural trade‑offs, dependency isolation, call conversion, version management, real‑world case studies, and future roadmap for large‑scale service optimization.

ByteDance Cloud Native
ByteDance Cloud Native
ByteDance Cloud Native
How Merge Compilation Supercharges ByteDance’s Microservices: Performance Gains and Technical Challenges

What is Merge Compilation?

Merge compilation combines two or more microservices into a single binary during the build phase, allowing them to run as one process. Calls that would normally use RPC are transformed into in‑process function calls, eliminating network, codec, and service‑governance overhead.

Benefits

Performance : Removes encoding/decoding, service governance, and network costs, reducing latency by 2‑15 ms.

Developer Efficiency : Teams continue to own their services; merging occurs only at deployment, preserving independent development workflows.

Flexibility : Services can be merged or kept separate as needed, enabling selective optimization.

Stability : Eliminates RPC‑related timeouts and overload issues, improving overall service stability.

Drawbacks

Runtime isolation is lost, and version updates require recompilation of the merged binary. The team has implemented mitigations to reduce these impacts.

Challenges

Challenges are grouped into three categories: fundamental challenges, optimizable points, and ideal‑state goals.

Fundamental Challenges

Isolation: handling incompatible dependencies, environment variable conflicts, permission isolation, and identity tracking.

Call Conversion: automating the transformation from RPC to function calls.

Usability: providing tooling to automate the merge process.

Stability: ensuring safe rollout with gray‑release capabilities.

Optimizable Points

Stability testing and rapid issue localization.

Version management: making downstream versions visible to upstream and vice‑versa.

Development workflow integration.

Compilation error diagnostics.

Local debugging without merged source code.

Ideal State

Addressing runtime isolation (resource, panic) and user acceptance of the merged binary model.

Dependency Isolation

Using Go modules, each service’s dependencies are downloaded into isolated directories. The

replace

directive maps remote imports to these local paths, achieving full dependency isolation.

<code>import (
    "namespaceA/github.com/cloudweGo/kitex"
    "namespaceB/github.com/cloudweGo/kitex"
)
replace github.com/cloudweGo/kitex => /tmp/kitex</code>

After isolation, environment variables, permissions, and identity can be managed separately for each merged service.

Dependency isolation diagram
Dependency isolation diagram

Call Conversion

The process extracts the server’s method implementations and injects them into the client. Kitex’s

Client

interface is used, and a custom

ServiceInlineClient

implements

Call

to invoke the local method directly.

<code>type Client interface {
    Call(ctx context.Context, method string, request, response interface{}) error
}
serverInfo := server.Main()
kc, err := client.NewServiceInlineClient(serviceInfo(), serverInfo, options…)</code>
Call conversion diagram
Call conversion diagram

Version Management

Merge compilation faces similar version‑management challenges as SDKs: downstream may not see upstream versions, and version selection can be complex. The platform now tracks dependency metadata, allowing automatic propagation of default versions and coordinated upgrades.

Version management UI
Version management UI

Case Study

A pair of services with 96 % traffic affinity and comparable CPU quotas were merged, yielding over 40 k core CPU savings and latency reductions of 2‑15 ms. Scaling this across 1.8 w links could save ~670 k cores.

Case study performance graph
Case study performance graph

Conclusion & Outlook

Merge compilation has proven viable at ByteDance, delivering substantial CPU, latency, and SLA improvements. Future work aims for top‑down platform‑driven adoption, integrating with business‑domain governance to automate microservice consolidation without code changes, thereby reducing architectural complexity and operational cost.

performance optimizationMicroservicesGoservice frameworkdependency isolationKitexmerge compilation
ByteDance Cloud Native
Written by

ByteDance Cloud Native

Sharing ByteDance's cloud-native technologies, technical practices, and developer events.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.