Library / Blogs
Meituan Blog (Chinese)
The engineering and technology blog of Meituan: posts on how it designs, builds and scales its systems. Written in Chinese.
By Meituan engineers · Meituan · Added 2026-10-12
All content belongs to Meituan engineers / Meituan. We only link to it and give credit. Report a problem
Learn this article
About 37 min left. Your work is saved as you go.
What you are about to study
Meituan wrote this to explain how they thought about a problem. You should know the basics: caching, queues and replication.
Ideas you will meet
- Distributed Systems
- Consensus, time, failure and the fundamentals of scale-out.
What we already know about this
Our own lessons on these ideas. Read them here before you start, so it makes sense.
Software Design Essentials · 11 minClean and hexagonal architectureKeep business rules independent of frameworks, databases and the web: the dependency rule, layers, and ports and adapters.Read here
The problem
In many applications, business rules are tangled with framework code, SQL and HTTP details. Then:
- You cannot test a rule without a database and a web server.
- Changing a framework or database means rewriting business logic.
- The code is organised around technology, not around what the system does.
Several architectures (hexagonal, onion, clean) solve this with the same idea: put business rules at the centre and keep details at the edges.
The dependency rule
100%Figure SDA-SDE-06-1 · Clean architecture: dependencies point inwards · © forcsguy.com
Source code dependencies point inwards only. Entities know nothing about use cases; use cases know nothing about the web or the database. Outer layers depend on inner ones, never the reverse.
Layer Contains Knows about Entities Core business objects and rules that would exist whatever the technology Nothing else Use cases Application-specific actions ("place order", "cancel subscription") that coordinate entities Entities and the ports they define Interface adapters Controllers, presenters, repositories' implementations, mappers Use cases Frameworks and drivers The web framework, database, message queue, UI Adapters Before: logic tangled in the controller
100%After: business rules in the middle
100%What changed
- Business rules can be tested without a web server or database
- The database or framework can be replaced at the edge
- There are more files and layers to maintain
Ports and adapters (hexagonal)
The application is the hexagon. It talks to the outside only through ports: interfaces it owns. Adapters translate between the outside world and the ports.
- Driving (inbound) ports: how the world calls the application (
PlaceOrder). Adapters: REST controller, CLI, message listener, test. - Driven (outbound) ports: what the application needs (
OrderRepository,PaymentGateway,Clock). Adapters: SQL implementation, payment provider client, fake for tests.
// Port owned by the application interface OrderRepository { save(order: Order): Promise<void>; byId(id: string): Promise<Order | null> } interface PaymentGateway { charge(cents: number, token: string): Promise<boolean> } // Use case: pure application logic class PlaceOrder { constructor(private orders: OrderRepository, private payments: PaymentGateway) {} async run(input: { items: Item[]; token: string }) { const order = Order.create(input.items); // entity enforces rules if (!(await this.payments.charge(order.totalCents, input.token))) throw new Error("Payment failed"); await this.orders.save(order); return order.id; } } // Adapters live outside, implementing the ports class SqlOrderRepository implements OrderRepository { /* uses a database */ } class StripeGateway implements PaymentGateway { /* calls the provider */ } // Composition root wires everything together at start-up const placeOrder = new PlaceOrder(new SqlOrderRepository(db), new StripeGateway(key));This is the dependency inversion principle from SOLID applied to a whole system.
Benefits
- Testable: run use cases with in-memory fakes, fast and without infrastructure.
- Replaceable details: change the database, queue or web framework by writing an adapter.
- Focus on the domain: the central code reads like the business process.
- Deferred decisions: you can postpone choosing a database.
Costs and cautions
- More structure: interfaces, mappers and wiring add code. For a small CRUD app it can be overkill.
- Mapping between layers (domain objects, database rows, API shapes) is repetitive; do it deliberately and avoid leaking database entities into the API.
- Do not create layers "because the diagram says so". Add a boundary where a real change or testing need exists.
- It is about dependencies, not folder names: a good folder layout helps but does not guarantee the rule is followed. Enforce it with tests or lint rules.
Related ideas
- Domain-driven design supplies the language for the centre of the hexagon (next lesson).
- Microservices are a deployment choice; each service can use this internal structure.
- Composition root: one place, at start-up, where concrete classes are chosen and injected.
Real-world reading
Related reading
- Cockroach Labs BlogCockroach Labs engineers · Cockroach LabsBlogs
- Fivetran BlogFivetran engineers · FivetranBlogs
- ClickHouse BlogClickHouse engineers · ClickHouseBlogs
- InfluxData BlogInfluxData engineers · InfluxDataBlogs
Show 6 moreShow fewer
- Elastic BlogElastic engineers · ElasticBlogs
- AWS Database BlogAWS database teams · Amazon Web ServicesBlogs
- How SQLite WorksSQLite team · SQLiteDocumentation
- AWS Big Data BlogAmazon Web Services engineers · Amazon Web ServicesBlogs
- Viget Engineering BlogViget engineers · VigetBlogs
- Meituan Blog (Chinese)Meituan engineers · MeituanBlogs
Go deeper on this
A path through videos, articles, other case studies and code on the same ideas as Meituan Blog (Chinese).
Warm upGet the vocabulary first.
Books · Free from the author
Concurrent and Distributed Systems (Cambridge lecture notes)
Eight lectures on time, broadcast, replication, consensus and transactions, with notes, slides and video. Free from the author under CC BY-SA.
University of CambridgeIntermediate
Books · Free from the author
Computer Networks: A Systems Approach
How networks are built and why: protocols, routing, congestion control and the internet's architecture. The authors publish it free online under CC BY 4.0.
Systems ApproachIntermediate
WatchHow others solve the same problem, on video.
Videos belong to their creators and play from YouTube. More on YouTube (opens in a new tab)
ReadEngineers explain it in their own words.
Blogs · Free from the author · Read here
Scalable Web Architecture and Distributed Systems
A full chapter on the building blocks of large websites: availability, performance, reliability, scalability, caches, proxies, indexes, load balancers and queues. Free to read here under CC BY 3.0.
The Architecture of Open Source ApplicationsBeginner40 min
Papers · Read here
Facebook’s photo storage
This paper describes Haystack, an object storage system optimized for Facebook’s Photos application. Facebook currently stores over 260 billion images, which translates to over 20 petabytes of data.
USENIXIntermediate
See it in another companyThe same ideas, a different system.
Case Studies · Read here
Aroma: Using ML for Code Recommendation at Facebook
Thousands of engineers write the code to create our apps, which serve billions of people worldwide. This is no trivial task—our services have grown so diverse and complex that the codebase contains…
FacebookIntermediate
Case Studies · Read here
Brooklin: Distributed Service for Near Real-Time Data Streaming at LinkedIn
Brooklin—a distributed service for streaming data in near real-time and at scale—has been running in production at LinkedIn since 2016, powering thousands of data streams and over 2 trillion messages per day. Today, w...
LinkedInIntermediate
Read the codeSee how it looks when it is real.
GitHub
Engineering Blogs
A huge directory of company engineering blogs to learn from real production systems.
kilimchoiIntermediate
GitHub
Awesome Scalability
Curated reading list of articles on the architecture of scalable, reliable systems.
binhnguyennusIntermediate
Keep learning
Loading community…