O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Practical Microservices

Book Description

Learn how to implement the microservice architecture using Java

About This Book

  • Leverage the power of microservices to build a flexible and efficient system in Java
  • See Docker and Spring Boot in practice to form easily deployable microservices
  • Hands-on approach throughout the book in order to familiarize and grasp the details

Who This Book Is For

This book is for Java developers who want to get started with microservices and implement it in their workplace. No knowledge of microservice is necessary.

What You Will Learn

  • The role of a discovery service and externalized configuration in the overall architecture
  • Use of message brokers for event driven microservices
  • How to intermix data management strategies across components
  • Implementing different types of tests in Spring Boot environment
  • Applying CI to our microservices style architecture
  • Walk through of monitoring and scaling the sample application

In Detail

A microservice architecture helps you build your application as a suite of different services. This approach has been widely adopted as it helps to easily scale up your application with reduced dependencies. This way if a part of your application is corrupted, it can be fixed easily thereby eliminating the possibility of completely shutting down your software. This book will teach you how to leverage Java to build scalable microservices. You will learn the fundamentals of this architecture and how to efficiently implement it practically.

We start off with a brief introduction to the microservice architecture and how it fares with the other architectures. The book dives deep into essential microservice components and how to set up seamless communication between two microservice end points. You will create an effective data model and learn different ways to test and deploy a microservices. You will also learn the best way to migrate your software from a monolith to a microservice architecture.

Finishing off with monitoring, scaling and troubleshooting, this book will set a solid foundation for you to start implementing microservices.

Style and approach

Starting with the fundamentals, this book explains all the essential concepts gradually with the help of numerous examples.

Table of Contents

  1. Preface
    1. What this book covers
    2. What you need for this book
    3. Who this book is for
    4. Conventions
    5. Reader feedback
    6. Customer support
      1. Downloading the example code
      2. Errata
      3. Piracy
      4. Questions
  2. Introduction to Microservices Architecture
    1. General microservices architecture
    2. Characteristics of microservice architecture
      1. Problem definition
      2. Solution
        1. How much proposed solution is aligned with microservice architecture?
    3. Challenges for a successful microservice architecture
      1. Debugging through logging
      2. Monitoring microservices
      3. Common libraries
      4. Messaging between services
      5. Deployment and versioning of microservices
    4. Future of microservices
      1. Serverless architecture
      2. Microservices as PaaS
    5. Dominance of microservice architecture over traditional architecture
    6. Huh? Doesn't it seem like SOA?
    7. Assorting large business domains into microservice components
      1. Organizing microservice components around business capabilities
    8. To go or not to go for microservices
      1. Organization buy-in
      2. Experience DevOps
      3. Analyze existing database model
      4. Automation and CI/CD
      5. Integration
      6. Security
      7. Example of successful migration
    9. Sample project (credit risk engine)
    10. Spring
    11. Spring Boot
      1. Things are easy with Spring Boot!
    12. Summary
  3. Defining Microservice Components
    1. Definition of a microservice
    2. Service Discovery and its role
      1. DNS
      2. Discovery service need
        1. Registry/deregistry of services
        2. Discovering other services
      3. Example of service discovery pattern
      4. Externalized configuration in the overall architecture
    3. API Gateway and its need
      1. Authentication
      2. Different protocol
      3. Load-balancing
      4. Request dispatching (including service discovery)
      5. Response transformation
      6. Circuit breaker
      7. Pros and cons of API Gateway
    4. Example of API Gateway
      1. Sample application used throughout the book
    5. Development of user registration microservice
      1. Configuration server
        1. Table structure
    6. Summary
  4. Communication between Microservices Endpoints
    1. How should microservices communicate with each other?
    2. Orchestration versus choreography
      1. Orchestration
      2. Choreography
    3. Synchronous versus asynchronous communication
      1. Synchronous communication
      2. Asynchronous communication
        1. Message-based/event-based asynchronous communication
        2. Implementing asynchronous communication with REST
        3. Implementing asynchronous communication with message broker
      3. Financial services
    4. Summary
  5. Securing Microservice Endpoints
    1. Security challenges in microservices
      1. Mix technology stack or legacy code presence
      2. Authentication and authorization (access control)
      3. Token-based security
      4. Responsibility of security
      5. Fear with orchestration style
      6. Communication among services
    2. Using JWT along with OpenID and OAuth 2.0
      1. OpenID
      2. OAuth 2.0
      3. JWT
        1. A few examples
          1. Header
      4. Sample application
    3. Summary
  6. Creating an Effective Data Model
    1. Data and modeling
      1. Comparison with a traditional data model
    2. Data model in monolithic architecture
    3. Data model in SOA
    4. Data model in microservice architecture
      1. Restricted tables for each microservice
      2. Database per microservice
      3. The Saga pattern
      4. Intermixing data technologies when needed
    5. Migrating a data model from monolithic to microservices
      1. Domain-Driven Design
      2. Methods of data model migration
        1. Views
        2. Clone table using trigger
        3. Event sourcing
        4. Sample application data model
    6. Summary
  7. Testing Microservices
    1. The purpose of testing in the microservices world
    2. Unit testing
    3. Integration testing
    4. Component (service) testing
    5. Contract testing
      1. Pact
      2. Spring Cloud Contract
    6. End-to-end testing
    7. One step further
    8. Summary
  8. Deploying Microservices
    1. Continuous integration
    2. Continuous delivery
    3. Configuring tools for CI and CD with our microservices
    4. Dockerizing our microservice
      1. Docker
        1. Docker engine
        2. Docker images
        3. Docker storage
      2. How things work in Docker
      3. Public, private, and official image repositories
      4. Docker versus VMs
      5. Installing Docker in Linux
    5. Using open source CI tools with our Dockerized microservices
    6. Summary
  9. Evolving the Existing System
    1. Where to start
      1. Architectural perspective and best practice
    2. Database perspective and best practice
    3. Sample application and its evolution
      1. User management service
      2. Cart/order service
      3. Payment service
      4. Shipping/tracking and communication service
      5. Recommendation service
      6. Scheduler service
    4. Summary
  10. Monitoring and Scaling
    1. Principles in monitoring a microservice system
      1. How and who will see the alerts
      2. Monitoring and channeling from the start
      3. Autoscale and autodiscovery
      4. Monitor front door
    2. Changing face of monitoring
    3. Logging helps in monitoring
    4. Principles in scaling a microservices system
      1. X axis
      2. Y axis
      3. Z axis
    5. Thoughts before scaling
    6. Practical options for both monitoring and scaling microservices
    7. Summary
  11. Troubleshooting
    1. Common issues with microservices
      1. Slow performance
      2. Different logging locations from different programming languages
      3. Coupling or dependency issues in multiple components
      4. Per-day deployment for more number of services
      5. Monitor many services for performance degradation or issues
      6. Relation between logs and different components
    2. Techniques to solve the common issue
      1. Steps to help with performance issues
      2. Handle logging in different locations and from different languages
      3. Dependencies between services
    3. High DevOps involvement
      1. Use smart tools
      2. Use smart developers
      3. Monitoring
    4. Summary