Sonic: Meituan's Hot Deployment IDEA Plugin – Architecture and Implementation

The article details Meituan's internal Sonic IDEA plugin for remote and local hot deployment, explaining why hot deployment is needed, its architecture, instrumentation techniques, DCEVM integration, file‑watching, class reloading, and support for Spring Bean, Spring XML and MyBatis, along with adoption statistics and performance benefits.

Meituan Technology Team
Meituan Technology Team
Meituan Technology Team
Sonic: Meituan's Hot Deployment IDEA Plugin – Architecture and Implementation

Introduction

Sonic is an internal Meituan IDEA plugin that enables hot deployment of Java applications without restarting the JVM. The article explains the motivation, design, and practical experience of deploying Sonic in a large‑scale production environment.

Why Hot Deployment?

Developers at Meituan restart services 5‑12 times daily, each taking 3‑8 minutes locally, and perform 3‑5 remote deployments per day, each lasting 20‑45 minutes. The plugin reduces code‑change latency to seconds, improving both self‑testing and integration testing workflows.

Sonic Capabilities

Sonic supports incremental deployment of multiple file types (Java classes, Spring Bean, Spring XML, MyBatis XML) and provides features such as traffic replay, remote invocation, and remote decompilation. In practice, a typical 20‑35 minute deployment cycle can be shortened to 5‑10 seconds.

Overall Architecture

Sonic consists of four components: a script side that prepares launch parameters, an IDEA plugin side that offers a UI, an Agent side that runs inside the target JVM, and a server side that collects metrics and reports failures. The components interact to form a complete deployment loop.

Agent and Instrumentation

The Agent uses the Java Instrumentation API to add transformers, retransform or redefine classes, and query loaded classes. Key methods include addTransformer, retransformClasses, and redefineClasses. The Agent can operate both via Premain (startup) and Agent‑on‑Attach (runtime) mechanisms.

public interface Instrumentation {
    void addTransformer(ClassFileTransformer transformer, boolean canRetransform);
    void addTransformer(ClassFileTransformer transformer);
    boolean removeTransformer(ClassFileTransformer transformer);
    boolean isRetransformClassesSupported();
    void retransformClasses(Class<?>... classes) throws UnmodifiableClassException;
    boolean isRedefineClassesSupported();
    void redefineClasses(ClassDefinition... definitions) throws ClassNotFoundException, UnmodifiableClassException;
    Class[] getAllLoadedClasses();
}

DCEVM Integration

Because JDK 7/8 cannot change class structure (add fields, methods, or change super‑classes), Sonic leverages the open‑source Dynamic Code Evolution Virtual Machine (DCEVM) to overcome this limitation, allowing addition or removal of members at runtime.

File Listening and Classpath Extension

Sonic watches two directories: /var/tmp/sonic/extraClasspath (custom classpath) and /var/tmp/sonic/classes (monitored files). When a file changes, the IDEA plugin pushes the update to the remote or local target, and the Agent loads the new class via an extended classpath URL, avoiding direct modification of JAR‑packed resources.

JVM Class Reload

The Agent creates ClassDefinition objects from the new bytecode and calls Instrumentation.redefineClasses. This triggers Spring’s transformation hooks to reload the affected components.

Spring Bean Reload

When a Java class changes, Spring scans the classpath, removes the old bean definition via BeanDefinitionRegistry.removeBeanDefinition, and destroys the bean instance. To handle parent‑child contexts, Sonic updates both the parent and child contexts, ensuring that downstream beans receive the refreshed instance. Different entry points (Spring MVC, Mthrift, Pigeon) use tailored reload strategies.

Spring XML Reload

Modifications to Spring XML trigger a full reload of the affected beans. Currently only simple bean additions or modifications are supported to avoid global AOP and processor side‑effects.

MyBatis Reload

Sonic tracks MyBatis Configuration objects, maps them to the Spring context, and reloads the configuration when related class or XML files change, achieving hot deployment for MyBatis mappers.

Adoption and Results

As of the article’s writing, Sonic is used by over 3,000 developers on more than 2,000 projects within Meituan, achieving a hot‑deployment success rate above 99.9 %. It received the “Best Efficiency Team” award in Meituan’s internal R&D platform.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

JavaInstrumentationspringMyBatisHot DeploymentIDEA PluginDCEVM
Meituan Technology Team
Written by

Meituan Technology Team

Over 10,000 engineers powering China’s leading lifestyle services e‑commerce platform. Supporting hundreds of millions of consumers, millions of merchants across 2,000+ industries. This is the public channel for the tech teams behind Meituan, Dianping, Meituan Waimai, Meituan Select, and related services.

0 followers
Reader feedback

How this landed with the community

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.