Building Microservices

Designing Fine-Grained Systems

This bestselling guide introduces the microservice architectural style and shows you how to design, integrate, test, deploy, and monitor your own autonomous services.

Author:

Sam Newman

Published Year:

2015-03-03

4.3
The New York Times Best Sellers Badge
4.3
(
23723
Ratings )
Play Audio Summary:
Building Microservices
Sam Newman
0:00
0:00
https://audiobooksupabase.blob.core.windows.net/audio/Building_Microservices_Sam_Newman_9781491950357.mp3

Key Takeaways: Building Microservices

Understanding Microservices: Breaking Down the Monolith for Agility

First, let's tackle the big question: What exactly *are* microservices, and why move away from the traditional monolithic approach?

At its heart, a microservice architecture structures an application as a collection of small, autonomous services, modeled around specific business capabilities, a core principle emphasized in 'Building Microservices'. Think about an online retail system. Instead of one giant application handling everything, 'Building Microservices' advocates for separate services for product catalog, user accounts, shopping cart, order processing, and payments. Each service is small, focused on doing one thing well.

Each microservice can be developed, deployed, and scaled independently. This is a game-changer, as highlighted in 'Building Microservices'. Remember our mansion analogy? With microservices, as 'Building Microservices' explains, if you want to renovate the 'user accounts' service – perhaps switch its database or rewrite it in a new programming language – you can do that without touching the 'product catalog' or 'order processing' services, as long as you maintain the agreed-upon communication contract, usually an API. This independent deployability drastically reduces the risk and increases the speed of releasing new features or updates.

Another key benefit is technology heterogeneity. Since services communicate over a network using technology-agnostic protocols like HTTP APIs, a concept detailed in 'Building Microservices', each service team can choose the best technology stack for their specific job. The 'product catalog' might use a fast NoSQL database optimized for reads, while the 'order processing' service might stick with a traditional relational database. 'Building Microservices' notes this flexibility allows teams to use the right tool for the job and experiment with new technologies without impacting the entire system.

Furthermore, microservices enhance resilience. If one service, say the 'recommendations' service, fails, it doesn't necessarily bring down the entire application, a key benefit discussed in 'Building Microservices'. The user might still be able to browse products, manage their cart, and place orders; they just won't see personalized recommendations for a while. Contrast this with a monolith where a single uncaught exception could potentially crash the entire application. This isolation of failure, central to the philosophy in 'Building Microservices', is crucial for building robust systems.

Conway's Law: Aligning Teams and Architecture for Microservice Success

This brings us neatly to our second key concept: the deep connection between organizational structure and system design, often summarized by Conway's Law.

Melvin Conway famously stated back in 1967 that 'organizations which design systems are constrained to produce designs which are copies of the communication structures of these organizations.' As 'Building Microservices' often points out, this means if you have separate teams for the user interface, the backend logic, and the database, you're highly likely to end up with a system architecture that mirrors this structure – a distinct UI layer, a backend application layer, and a database layer, often resulting in a layered monolith. Communication *between* these layers, as 'Building Microservices' warns, becomes formal and potentially slow, mirroring the communication overhead between the teams.

Microservices often thrive in organizations that embrace what's called 'Conway's Law in Reverse.' Instead of letting the existing organizational structure dictate the architecture, 'Building Microservices' suggests you intentionally structure your teams to align with the desired architecture. If you want small, independent services focused on business capabilities, you create small, cross-functional teams, often called 'feature teams' or 'squads,' that own a specific service or set of related services end-to-end. Such a team, as described in 'Building Microservices', typically includes developers, testers, operations expertise, and perhaps a product owner.

This concept of service ownership is absolutely critical. When teams own services long-term, a practice strongly recommended in 'Building Microservices', they are incentivized to build them well, make them reliable, and manage their technical debt, because they are the ones who will be woken up at 3 AM if it breaks. Contrast this with project-based teams that build something and then hand it off to a separate maintenance team – the incentives, as 'Building Microservices' highlights, are very different.

Ignoring Conway's Law is often a recipe for friction and pain. The key takeaway here, echoed in 'Building Microservices', is that moving to microservices isn't just a technical decision; it often requires, or at least strongly benefits from, a corresponding shift in team structure and culture towards autonomous, business-capability-aligned teams, a point emphasized throughout 'Building Microservices'. Clear ownership can sometimes be challenging, requiring conscious effort in governance.

Navigating Microservice Testing: From Unit Tests to Consumer-Driven Contracts

Okay, so we have our independently deployable services built by autonomous teams. How do we ensure they actually work, especially together?

Unit tests remain foundational. They test individual components or classes within a single service in isolation, ensuring the internal logic works correctly, a basic practice also relevant according to 'Building Microservices'. They are fast, reliable, and provide precise feedback. Test-Driven Design (TDD), often mentioned alongside microservices development in resources like 'Building Microservices', is often a great practice here.

The middle layer, often called service tests or integration tests (though terminology varies), becomes incredibly important. These tests verify a service's behavior without involving its internal components directly. Crucially, they often test the service *in isolation* from its real dependencies, a technique covered in 'Building Microservices'. How? Through the use of test doubles like mocks and stubs. The goal, as 'Building Microservices' clarifies, is to verify the service behaves correctly given certain inputs and responses from its collaborators, without the brittleness of testing against live dependencies.

Now, what about those end-to-end tests? These are the tests that simulate a full user journey, potentially traversing multiple services. While they seem appealing because they test the system 'as a user would,' 'Building Microservices' warns they come with significant downsides in a microservices context. They tend to be slow, brittle (a failure in *any* service along the path can break the test), and flaky. Debugging failures, as noted in 'Building Microservices', can be a nightmare, involving tracing requests across multiple service logs.

Many teams find more value in focusing on robust service-level tests and introducing Consumer-Driven Contracts (CDCs). CDCs, a pattern gaining traction and discussed in 'Building Microservices', turn the testing relationship on its head. The *consumer* service defines the expectations it has of its *provider* service in a contract. This contract is then used to automatically verify that the provider service actually meets those expectations, often integrated into the provider's build pipeline. If the payment service team makes a change that breaks the contract... their build fails *before* deployment, preventing integration issues in production, a key benefit highlighted in 'Building Microservices'.

Achieving Scale and Resilience: Essential Patterns for Microservices

Building and testing these services is one thing, but running them effectively at scale introduces another set of challenges.

Microservices offer granular scaling – you can scale just the services under heavy load. As 'Building Microservices' explains, if your 'product search' service is getting hammered, you can add more instances of just that service, without needing to scale the entire application as you would with a monolith. This can lead to much more efficient resource utilization compared to monoliths, a point often made in 'Building Microservices'. Scaling can involve 'going bigger' or 'spreading the risk' with multiple instances and autoscaling.

Scaling databases is often a major hurdle. A shared database across multiple services is generally considered an anti-pattern in microservices, as 'Building Microservices' strongly advises, because it creates tight coupling. Each service should ideally own its data store. But how do you scale these individual data stores? Techniques like sharding add complexity. A powerful pattern discussed in 'Building Microservices' is Command Query Responsibility Segregation, or CQRS, which separates update models (Command) from read models (Query) for independent optimization.

Caching is another vital scaling technique. Caching can happen at multiple levels: client-side, proxy layer (CDN, Varnish), or server-side (Redis, Memcached). Effective caching, as detailed in 'Building Microservices', can dramatically reduce load on downstream services and databases. HTTP caching headers provide standardization. However, caching introduces its own complexities, particularly around cache invalidation and potential cache poisoning. Keeping caching strategies simple initially is often wise, a practical tip found in 'Building Microservices'.

Failure is a *when*, not an *if*, in distributed systems. Building resilient systems means designing for failure, a central theme in 'Building Microservices'. Timeouts are fundamental: never wait indefinitely for a response. The Circuit Breaker pattern, explained thoroughly in 'Building Microservices', is crucial here. It monitors calls, trips on high failure rates to prevent cascading failures, and uses a half-open state to test recovery.

Bulkheads are another important pattern, inspired by ship design, and covered in 'Building Microservices'. This means isolating resources (like connection or thread pools) for different dependencies, so slowness in calls to service A doesn't impact calls to service B. Idempotency is also key for resilience, ensuring operations can be retried safely. Finally, how do services find each other? This is the role of Service Discovery, often using dynamic registries like Consul or Eureka, as recommended in 'Building Microservices', which track healthy, available service instances.

Securing Microservices: Defense in Depth in a Decentralized World

Our final exploration area is Security, which becomes arguably more complex in a distributed microservices world.

Relying solely on perimeter security ('allow everything inside the perimeter') is dangerous. With a monolith, security often focused on the outer boundary. But with microservices, as 'Building Microservices' points out, you have potentially hundreds of services communicating over internal networks. A breach of one service could potentially grant access to many others. Relying solely on perimeter security is insufficient; 'Building Microservices' advocates for defense in depth.

Service-to-service authentication and authorization become critical. How does the 'order processing' service know that the call it received *really* came from the 'shopping cart' service and that the cart service is authorized to place orders? Several approaches exist, detailed in resources like 'Building Microservices', including HTTP Basic Auth (over HTTPS), client certificates, API keys, and HMAC. More robust solutions often involve standards like SAML or OpenID Connect, potentially using a central identity provider to issue tokens (like JWTs - JSON Web Tokens) that services can validate, a common pattern discussed in 'Building Microservices'.

This brings up the 'Confused Deputy Problem.' Imagine the 'shopping cart' service calls the 'order processing' service on behalf of User A. The order service trusts the cart service, but how does it ensure the cart service isn't mistakenly acting on behalf of User B, or exceeding User A's permissions? 'Building Microservices' explains this requires careful propagation of security context across service calls. The calling service (the deputy) needs to securely pass the original user's identity/permissions, and the receiving service needs to enforce authorization based on that original context, a crucial point highlighted in 'Building Microservices'.

Securing data at rest is also vital. Sensitive data stored in databases should be encrypted, following best practices outlined in 'Building Microservices'. Choose well-known, standard encryption algorithms. Key management is paramount – protect your encryption keys rigorously, as 'Building Microservices' emphasizes. Consider encrypting backups as well. Decrypting data only when absolutely necessary ('decrypt on demand') minimizes exposure. Foundational practices like firewalls, logging, patching, and secure coding (OWASP) remain crucial.

Microservices Trade-offs and the Architect as Town Planner

What really stands out from exploring these ideas, often synthesized in works like Newman's, is that microservices are not a silver bullet.

They introduce their own complexities, particularly around distributed systems operations, data consistency, and testing. Adopting microservices requires significant investment in automation – build pipelines, deployment, monitoring – and often a cultural shift towards DevOps practices and team autonomy, points frequently made in 'Building Microservices'. They might not be the right choice for every project, especially small applications or teams not ready for the operational overhead, a caution also found in 'Building Microservices'.

The decision involves trade-offs. You gain independent deployability, technology flexibility, and resilience, benefits detailed in 'Building Microservices', but you trade the apparent simplicity of a monolith for the complexities of a distributed system, a core consideration discussed in 'Building Microservices'. Understanding this balance is key before embarking on a microservice journey.

What surprised me revisiting these concepts is how much the 'town planner' analogy resonates. It shifts the architect's focus from dictating specifics to enabling productive constraints and fostering a healthy ecosystem, an idea explored in 'Building Microservices'. The architect focuses on defining boundaries, establishing communication protocols and standards, and ensuring cross-cutting concerns are addressed. It emphasizes interfaces, standards, and observability – knowing what's happening between the zones, a concept central to managing systems according to 'Building Microservices'.

This changes how we should think about building large systems. It's less about crafting a single, perfect, static artifact, and more about cultivating a dynamic, evolving system composed of well-defined, independent parts, a vision presented in 'Building Microservices'. It requires embracing automation, designing for failure, and aligning technology with team structure via Conway's Law. Ask yourself: could breaking this down help us move faster and build a more resilient, scalable system? It’s a complex journey, as 'Building Microservices' makes clear, but offers potential.

What the Book About

  • Addresses the challenges of large, complex monolithic systems becoming hard to change and deploy.
  • Defines microservices as structuring an application as a collection of small, autonomous services modeled around business capabilities. Concepts often detailed in books like Building Microservices.
  • Highlights key benefits: Independent deployability (faster, safer releases), technology heterogeneity (right tool for the job), and enhanced resilience (fault isolation).
  • Acknowledges the shift to distributed system complexities: network latency, potential failures, and the need for strategies like eventual consistency.
  • Explains the architect's role shifting to a "Town Planner": focusing on boundaries, communication standards, and overall system health rather than internal service details.
  • Introduces Conway's Law: How organizational structure inherently shapes system design.
  • Advocates structuring teams (small, cross-functional, service-owning) to align with the desired microservice architecture (Reverse Conway), a core idea in Building Microservices.
  • Discusses testing strategies: Emphasizing unit and isolated service tests (using test doubles) over brittle end-to-end tests, potentially using Consumer-Driven Contracts.
  • Covers scaling techniques: Granular scaling of specific services, database scaling patterns (like CQRS), and multi-level caching strategies, often explored in Building Microservices.
  • Details essential resilience patterns: Designing for failure with Timeouts, Circuit Breakers, Bulkheads, and ensuring operational Idempotency.
  • Explains the need for Service Discovery mechanisms for services to locate each other dynamically in changing environments. Guidance can be found in resources like Building Microservices.
  • Addresses increased security complexity: Requiring defense in depth, robust service-to-service authentication/authorization, managing the Confused Deputy problem, and securing data at rest. Security is a major topic within Building Microservices.
  • Stresses that microservices are not a silver bullet: They involve trade-offs, demanding significant investment in automation, monitoring, and often a cultural shift, as emphasized in Building Microservices.

Who Should Read the Book

  • Software developers and engineers currently working on or struggling with large, complex monolithic applications that have become difficult to change, test, and deploy. They will find value in understanding how breaking down systems, as detailed in works like Building Microservices, can improve development speed and reduce risk.
  • Software architects responsible for designing system structures. The content provides deep insights into the microservice architectural style, contrasting it with monoliths, discussing trade-offs, and introducing the 'town planner' analogy for architects in a microservices world, a concept often related to books like Building Microservices.
  • Technical leads and engineering managers who need to understand the organizational implications of architectural choices. The discussion on Conway's Law and the need for autonomous, cross-functional teams aligned with service boundaries is crucial for structuring teams effectively when adopting microservices, a key takeaway from resources like Building Microservices.
  • DevOps, SREs, and Operations personnel who manage the deployment, scaling, resilience, and monitoring of software systems. The text covers essential operational patterns like independent scaling, circuit breakers, bulkheads, service discovery, and the complexities of monitoring distributed systems, all relevant when managing architectures derived from principles in Building Microservices.
  • Teams and individuals looking for effective testing strategies in distributed environments. The explanation of unit tests, service/integration tests (with mocks/stubs), the pitfalls of end-to-end tests, and the value of Consumer-Driven Contracts provides practical guidance often discussed alongside Building Microservices.
  • Developers and security professionals concerned with securing distributed systems. The overview of service-to-service authentication/authorization, data security, and the need for defense-in-depth highlights challenges specific to microservices, a critical aspect covered when discussing Building Microservices.
  • Organizations considering a transition from monolithic architectures and needing a balanced view of the benefits (e.g., independent deployability, technology heterogeneity, resilience) and the inherent complexities (distributed systems challenges, operational overhead, testing difficulties) associated with microservices, as realistically portrayed in discussions around Building Microservices.

Plot Devices

Characters

FAQ

How does 'Microservice Architecture' function according to Sam Newman's 'Building Microservices'?

  • Service Decomposition: Microservice Architecture involves structuring an application as a collection of small, autonomous services modeled around a business domain.
  • Independent Deployability: Instead of a single monolithic deployment, different features like 'order management' or 'user profile' become separate services that can be deployed independently.
  • Organizational Alignment: This approach enhances organizational agility and scalability by allowing smaller teams to own services and enabling technology diversity.

What is the significance of 'Bounded Context' in designing microservices as explained in 'Building Microservices'?

  • Model Integrity: A Bounded Context, originating from Domain-Driven Design, defines an explicit boundary within which a particular domain model is consistent and well-understood.
  • Service Boundaries: In 'Building Microservices', aligning service boundaries with Bounded Contexts helps ensure services are cohesive and loosely coupled, like separating 'product catalog' logic from 'customer reviews'.
  • Ubiquitous Language: Using Bounded Contexts promotes clearer communication and understanding within development teams by establishing a specific, shared language for each domain.

What practical applications of an 'API Gateway' are highlighted in Sam Newman's 'Building Microservices'?

  • Single Entry Point: An API Gateway acts as a single entry point for all client requests, routing them to the appropriate backend microservice.
  • Cross-Cutting Concerns: It can handle cross-cutting concerns like authentication, SSL termination, and rate limiting, simplifying the individual microservices, as shown in 'Building Microservices'.
  • Interface Stability: Using an API Gateway provides a stable interface for clients while allowing backend services to evolve, enhancing system resilience and maintainability.

How does 'Building Microservices' advocate for 'Decentralized Data Management'?

  • Data Sovereignty: Decentralized Data Management means each microservice is responsible for its own domain data, often using its own database.
  • Polyglot Persistence: 'Building Microservices' illustrates this with examples like an 'order service' managing order data in its own database, separate from the 'customer service' database.
  • Loose Coupling: This principle enhances service autonomy and scalability but requires careful handling of data consistency across services, often using event-based patterns.

How does 'Service Discovery' work within microservices according to Sam Newman's 'Building Microservices'?

  • Dynamic Addressing: Service Discovery provides mechanisms for microservices to find the network locations (IP address and port) of other services they need to communicate with.
  • Discovery Patterns: Sam Newman discusses patterns like client-side and server-side discovery, using tools like Consul or Eureka to register and locate service instances dynamically.
  • System Resilience: Effective Service Discovery is crucial for the resilience and scalability of a microservice architecture, allowing services to adapt to instance failures and scaling events.

Why is 'Continuous Delivery' considered crucial in 'Building Microservices' by Sam Newman?

  • Automated Pipeline: Continuous Delivery is a software development practice where code changes are automatically built, tested, and prepared for release to production.
  • Deployment Frequency: In 'Building Microservices', CD is essential for managing the complexity of deploying many independent services frequently and reliably.
  • Reduced Risk: Implementing Continuous Delivery enables faster feedback loops, reduces deployment risk, and increases team velocity in a microservices environment.

How does Sam Newman's 'Building Microservices' approach 'Fault Tolerance' in distributed systems?

  • Resilience Design: Fault Tolerance is the ability of a system to continue operating properly in the event of the failure of some of its components.
  • Failure Isolation: 'Building Microservices' emphasizes patterns like Circuit Breakers, Timeouts, and Bulkheads to prevent cascading failures between services.
  • Graceful Degradation: Designing for fault tolerance ensures that the failure of one non-critical service does not bring down the entire application, improving overall system availability.

What are the key aspects of 'Monitoring and Logging' discussed in 'Building Microservices'?

  • System Observability: Monitoring and Logging involve collecting, aggregating, and analyzing data about the health and performance of microservices.
  • Centralized Tools: The book highlights the need for centralized logging (e.g., ELK stack), distributed tracing, and health check endpoints to understand behavior across multiple services.
  • Operational Insight: Effective Monitoring and Logging are vital for troubleshooting issues, understanding system performance, and ensuring reliability in complex microservice landscapes.

Inspirational Quotes & Insights

Find 8 original quotes from the book Building Microservices

Mindmap of Building Microservices

Download PDF of Building Microservices

To save Building Microservices's summary for later, download the free PDF. You can print it out, or read offline at your convenience.

Download EPUB of Building Microservices

To read Building Microservices's summary on your e-reader device or app, download the free EPUB. The .epub digital book format is ideal for reading ebooks on phones, tablets, and e-readers.

🏅 Best Sellers in 2025

Wisdom Validated by Millions

By

Elizabeth Catte

Pure America

By

Bruce Weinstein

Instant Pot Bible

By

Nathaniel Philbrick

Valiant Ambition

By

Robin Wall Kimmerer

Braiding Sweetgrass

By

Ezra Klein

Abundance

By

Flatiron Author to be Revealed March 2025

Untitled Flatiron

By

Julie Holland M.D.

Good Chemistry

By

Richard Cooper

The Unplugged Alpha