究竟什么是微服务?
What Even Are Microservices?

原始链接: https://var0.xyz/posts/what-even-are-microservices.html

微服务常被视为“优秀架构”的首选,但其缺乏具体的定义。作者认为,微服务不应被视为一种技术抽象,而是一种**组织工具**。 虽然许多团队转向微服务是为了解决技术难题(如构建速度慢或部署困难),但这些问题通常在单体架构内也能解决。微服务的真正价值在于当组织规模扩大,各独立团队需要自主权并能按各自时间表发布时。通过使服务边界与团队边界对齐,企业能获得必要的运营灵活性。 然而,这种自主权代价高昂。转向分布式系统会引入巨大的复杂性,包括网络延迟、部分故障及一致性挑战。此外,技术重构被复杂的跨团队沟通、版本管理和协作数据库变更所取代。 归根结底,微服务并非“神奇”的技术解决方案。它是一种战略权衡:为了解决人力规模的协作问题,你牺牲了单体架构的简洁与集中化。在采用微服务之前,组织必须确保是为了解决组织扩展问题,而非仅仅追逐技术潮流。

这篇 Hacker News 讨论探讨了“单体架构与微服务”之争,用户认为这种二分法往往是伪命题。许多人认为,微服务主要受**康威定律**驱动,即系统边界应反映组织结构,以确保团队能够独立工作。 讨论中的关键点包括: * **组织与技术的区别**:尽管有些人将微服务视为团队解耦的手段,但另一些人认为,架构良好的单体应用可以通过内部 API 和静态分析实现同样的模块化。 * **权衡**:支持者强调了微服务能提高稳健性,并将关键业务逻辑与易故障组件隔离开来。持怀疑态度者则指出,分布式系统的管理复杂性增加,特别是在可观测性、日志记录和依赖追踪方面。 * **“合适的规模”**:多位贡献者指出,“微”是一个用词不当的说法;服务规模应基于业务需求,而非盲目追求微小。 * **现代替代方案**:一些参与者提倡“模块化单体”,即将代码整合在一起但保持独立部署,旨在获得微服务的组织收益,同时避免分布式系统带来的运维开销。 总体而言,社区对“为了微服务而微服务”的做法持怀疑态度,并强调其价值取决于具体的规模和团队需求。
相关文章

原文

It's almost impossible to have a conversation about software architecture without someone bringing up microservices. Just look at the discussion over my last post. They have become the default example of both "good architecture" and "over-engineering," depending on who you ask.

What's interesting is that everyone seems to recognize a microservice when they see one, yet almost nobody can explain what actually makes something a microservice.

The impossible definition

How small is micro? Should a service do exactly one thing? Two? Is there a maximum number of lines of code? A thousand? Ten thousand? Nobody has convincing answers, because there aren't any.

The industry has spent years trying to define microservices by technical characteristics, but those characteristics are surprisingly vague and fuzzy. The boundaries aren't measured in responsibilities or number of deployments per day. They're measured somewhere else entirely.

And that's the important realization: microservices aren't primarily a technical abstraction.

The problem they're actually solving

Listen to the reasons people usually give for moving away from a monolith: deployments are slow, tests take too long, builds are painful. These are real problems, but none of them require microservices. Every single one can be improved while staying inside a monolith.

So why do organizations migrate anyway?

Because the bottleneck usually isn't technical. It's organizational.

As companies grow, dozens or hundreds of engineers need to work independently. Teams need ownership. They need to release on their own schedules without constantly coordinating with everyone else. Microservices create boundaries that mirror organizational boundaries. That's their real value.

Every benefit comes with a bill

Engineering is the art of managing trade-offs. Microservices are no exception.

You gain autonomy, but you lose centralization. Inside a monolith it's easy to answer questions like "Which dependencies are we shipping?"; or "Is this piece of code still used?" Static analysis can often tell you. Once the code is spread across dozens of independent services, those answers become much harder to obtain.

The same pattern repeats everywhere. Communication between functions becomes communication over the network. A method call becomes an HTTP request. A compiler error becomes a runtime failure. Every distributed system problem — latency, retries, partial failures, serialization, consistency — suddenly becomes part of your application.

None of these costs are surprising. They're simply the price you pay for the flexibility that distributed systems provide.

The hidden communication cost

When people talk about communication overhead, they usually think about APIs talking to each other. That's only half the story.

The teams now have to communicate too.

Changing an API is no longer a refactor. It's a negotiation. Consumers need advance notice. Versioning becomes necessary. Old versions have to remain alive while everyone migrates. Database changes become coordinated efforts instead of straightforward commits.

The software isn't the only thing that's distributed anymore. The decision making is as well.

Choose them for the right reason

None of this is an argument against microservices. They're an excellent architectural choice in the right environment. Many successful companies simply couldn't operate without them.

But it's worth being honest about why they work.

If your primary problem is organizational scaling, microservices might be exactly the right answer. If your problem is purely technical, you should first ask whether you're reaching for a solution that's far larger than the problem itself.

Architectures become much easier to reason about once we stop pretending microservices are magic technical tools. They're organizational tools with technical consequences.


I made a video version of this argument, if you'd rather watch it: What even are microservices?

Thanks for reading.

联系我们 contact @ memedata.com