Home Page Icon
Home Page
Table of Contents for
Table of Contents
Close
Table of Contents
by David Gonzalez, Rajesh RV, Sourabh Sharma
Microservices: Building Scalable Software
Microservices: Building Scalable Software
Table of Contents
Microservices: Building Scalable Software
Microservices: Building Scalable Software
Credits
Preface
What this learning path covers
What you need for this learning path
Who this learning path is for
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. Module 1
1. A Solution Approach
Evolution of µServices
Monolithic architecture overview
Limitation of monolithic architecture versus its solution with µServices
One dimension scalability
Release rollback in case of failure
Problems in adopting new technologies
Alignment with Agile practices
Ease of development – could be done better
Microservices build pipeline
Deployment using a container such as Docker
Containers
Docker
Docker's architecture
Docker image
Docker container
Deployment
Summary
2. Setting Up the Development Environment
Spring Boot configuration
Spring Boot overview
Adding Spring Boot to the rest sample
Adding a Jetty-embedded server
Sample REST program
Writing the REST controller class
@RestController
@RequestMapping
@RequestParam
@PathVariable
Making a sample REST app executable
Setting up the application build
Running the Maven tool
Executing with the Java command
REST API testing using the Postman Chrome extension
Some more positive test scenarios
Negative test scenarios
NetBeans IDE installation and setup
References
Summary
3. Domain-Driven Design
Domain-driven design fundamentals
Building blocks
Ubiquitous language
Multilayered architecture
Presentation layer
Application layer
Domain layer
Infrastructure layer
Artifacts of domain-driven design
Entities
Value objects
Frequently asked questions
Services
Aggregates
Repository
Factory
Modules
Strategic design and principles
Bounded context
Continuous integration
Context map
Shared kernel
Customer-supplier
Conformist
Anticorruption layer
Separate ways
Open host service
Distillation
Sample domain service
Entity implementation
Repository implementation
Service implementation
Summary
4. Implementing a Microservice
OTRS overview
Developing and implementing µServices
Restaurant µService
Controller class
API versioning
Service classes
Repository classes
Entity classes
Booking and user services
Registration and Discovery service (Eureka service)
Execution
Testing
References
Summary
5. Deployment and Testing
An overview of microservice architecture using Netflix OSS
Load balancing
Client-side load balancing
Server-side load balancing
Circuit breaker and monitoring
Using Hystrix's fallback methods
Monitoring
Setting up the Hystrix Dashboard
Setting up Turbine
Microservice deployment using containers
Installation and configuration
Docker Machine with 4 GB
Building Docker images with Maven
Running Docker using Maven
Integration testing with Docker
Pushing the image to a registry
Managing Docker containers
References
Summary
6. Securing Microservices
Enabling Secure Socket Layer
Authentication and authorization
OAuth 2.0
Usage of OAuth
OAuth 2.0 specification – concise details
OAuth 2.0 roles
Resource owner
Resource server
Client
Authorization server
OAuth 2.0 client registration
Client types
Confidential client type
Public client type
Web application
User agent-based application
Native application
Client identifier
Client authentication
OAuth 2.0 protocol endpoints
Authorization endpoint
Token endpoint
Redirection endpoint
OAuth 2.0 grant types
Authorization code grant
Authorization code requests and responses
Implicit grant
Implicit grant requests and responses
Resource owner password credentials grant
Client credentials grant
OAuth implementation using Spring Security
Authorization code grant
Implicit grant
Resource owner password credential grant
Client credentials grant
References
Summary
7. Consuming Services Using a Microservice Web App
AngularJS framework overview
MVC
MVVM
Modules
Providers and services
Scopes
Controllers
Filters
Directives
UI-Router
Development of OTRS features
Home page/restaurant list page
index.html
app.js
restaurants.js
restaurants.html
Search Restaurants
Restaurant details with reservation option
restaurant.html
Login page
login.html
login.js
Reservation confirmation
Setting up the web app
Summary
8. Best Practices and Common Principles
Overview and mindset
Best practices and principals
Nanoservice (not recommended), size, and monolithic
Continuous integration and deployment
System/end-to-end test automation
Self-monitoring and logging
A separate data store for each microservice
Transaction boundaries
Microservices frameworks and tools
Netflix Open Source Software (OSS)
Build – Nebula
Deployment and delivery – Spinnaker with Aminator
Service registration and discovery – Eureka
Service communication – Ribbon
Circuit breaker – Hystrix
Edge (proxy) server – Zuul
Operational monitoring – Atlas
Reliability monitoring service – Simian Army
AWS resource monitoring – Edda
On-host performance monitoring – Vector
Distributed configuration management – Archaius
Scheduler for Apache Mesos – Fenzo
Cost and cloud utilization – Ice
Other security tools – Scumblr and FIDO
Scumblr
Fully Integrated Defence Operation (FIDO)
References
Summary
9. Troubleshooting Guide
Logging and ELK stack
A brief overview
Elasticsearch
Logstash
Kibana
ELK stack setup
Installing Elasticsearch
Installing Logstash
Installing Kibana
Tips for ELK stack implementation
Use of correlation ID for service calls
Let's see how we can tackle this problem
Dependencies and versions
Cyclic dependencies and their impact
It needs to be analyzed while designing the system
Maintaining different versions
Let's explore more
References
Summary
2. Module 2
1. Demystifying Microservices
The evolution of microservices
Business demand as a catalyst for microservices evolution
Technology as a catalyst for the microservices evolution
Imperative architecture evolution
What are microservices?
Microservices – the honeycomb analogy
Principles of microservices
Single responsibility per service
Microservices are autonomous
Characteristics of microservices
Services are first-class citizens
Characteristics of services in a microservice
Microservices are lightweight
Microservices with polyglot architecture
Automation in a microservices environment
Microservices with a supporting ecosystem
Microservices are distributed and dynamic
Antifragility, fail fast, and self-healing
Microservices examples
An example of a holiday portal
A microservice-based order management system
An example of a travel agent portal
Microservices benefits
Supports polyglot architecture
Enabling experimentation and innovation
Elastically and selectively scalable
Allowing substitution
Enabling to build organic systems
Helping reducing technology debt
Allowing the coexistence of different versions
Supporting the building of self-organizing systems
Supporting event-driven architecture
Enabling DevOps
Relationship with other architecture styles
Relations with SOA
Service-oriented integration
Legacy modernization
Service-oriented application
Monolithic migration using SOA
Relations with Twelve-Factor apps
A single code base
Bundling dependencies
Externalizing configurations
Backing services are addressable
Isolation between build, release, and run
Stateless, shared nothing processes
Exposing services through port bindings
Concurrency to scale out
Disposability with minimal overhead
Development and production parity
Externalizing logs
Package admin processes
Microservice use cases
Microservices early adopters
The common theme is monolithic migrations
Summary
2. Building Microservices with Spring Boot
Setting up a development environment
Developing a RESTful service – the legacy approach
Moving from traditional web applications to microservices
Using Spring Boot to build RESTful microservices
Getting started with Spring Boot
Developing the Spring Boot microservice using the CLI
Developing the Spring Boot Java microservice using STS
Examining the POM file
Examining Application.java
Examining application.properties
Examining ApplicationTests.java
Testing the Spring Boot microservice
Developing the Spring Boot microservice using Spring Initializr – the HATEOAS example
What's next?
The Spring Boot configuration
Understanding the Spring Boot autoconfiguration
Overriding default configuration values
Changing the location of the configuration file
Reading custom properties
Using a .yaml file for configuration
Using multiple configuration profiles
Other options to read properties
Changing the default embedded web server
Implementing Spring Boot security
Securing microservices with basic security
Securing a microservice with OAuth2
Enabling cross-origin access for microservices
Implementing Spring Boot messaging
Developing a comprehensive microservice example
Spring Boot actuators
Monitoring using JConsole
Monitoring using SSH
Configuring application information
Adding a custom health module
Building custom metrics
Documenting microservices
Summary
3. Applying Microservices Concepts
Patterns and common design decisions
Establishing appropriate microservice boundaries
Autonomous functions
Size of a deployable unit
Most appropriate function or subdomain
Polyglot architecture
Selective scaling
Small, agile teams
Single responsibility
Replicability or changeability
Coupling and cohesion
Think microservice as a product
Designing communication styles
Synchronous style communication
Asynchronous style communication
How to decide which style to choose?
Orchestration of microservices
How many endpoints in a microservice?
One microservice per VM or multiple?
Rules engine – shared or embedded?
Role of BPM and workflows
Can microservices share data stores?
Setting up transaction boundaries
Altering use cases to simplify transactional requirements
Distributed transaction scenarios
Service endpoint design consideration
Contract design
Protocol selection
Message-oriented services
HTTP and REST endpoints
Optimized communication protocols
API documentations
Handling shared libraries
User interfaces in microservices
Use of API gateways in microservices
Use of ESB and iPaaS with microservices
Service versioning considerations
Design for cross origin
Handling shared reference data
Microservices and bulk operations
Microservices challenges
Data islands
Logging and monitoring
Dependency management
Organization culture
Governance challenges
Operation overheads
Testing microservices
Infrastructure provisioning
The microservices capability model
Core capabilities
Infrastructure capabilities
Supporting capabilities
Process and governance capabilities
Summary
4. Microservices Evolution – A Case Study
Reviewing the microservices capability model
Understanding the PSS application
Business process view
Functional view
Architectural view
Design view
Implementation view
Deployment view
Death of the monolith
Pain points
Stop gap fix
Retrospection
Shared data
Single database
Native queries
Stored procedures
Domain boundaries
Microservices to the rescue
The business case
Plan the evolution
Evolutionary approach
Identification of microservices boundaries
Analyze dependencies
Events as opposed to query
Events as opposed to synchronous updates
Challenge requirements
Challenge service boundaries
Final dependency graph
Prioritizing microservices for migration
Data synchronization during migration
Managing reference data
User interfaces and web applications
Session handling and security
Test strategy
Building ecosystem capabilities
Migrate modules only if required
Target architecture
Internal layering of microservices
Orchestrating microservices
Integration with other systems
Managing shared libraries
Handling exceptions
Target implementation view
Implementation projects
Running and testing the project
Summary
5. Scaling Microservices with Spring Cloud
Reviewing microservices capabilities
Reviewing BrownField's PSS implementation
What is Spring Cloud?
Spring Cloud releases
Components of Spring Cloud
Spring Cloud and Netflix OSS
Setting up the environment for BrownField PSS
Spring Cloud Config
What's next?
Setting up the Config server
Understanding the Config server URL
Accessing the Config Server from clients
Handling configuration changes
Spring Cloud Bus for propagating configuration changes
Setting up high availability for the Config server
Monitoring the Config server health
Config server for configuration files
Completing changes to use the Config server
Feign as a declarative REST client
Ribbon for load balancing
Eureka for registration and discovery
Understanding dynamic service registration and discovery
Understanding Eureka
Setting up the Eureka server
High availability for Eureka
Zuul proxy as the API gateway
Setting up Zuul
High availability of Zuul
High availability of Zuul when the client is also a Eureka client
High availability when the client is not a Eureka client
Completing Zuul for all other services
Streams for reactive microservices
Summarizing the BrownField PSS architecture
Summary
6. Autoscaling Microservices
Reviewing the microservice capability model
Scaling microservices with Spring Cloud
Understanding the concept of autoscaling
The benefits of autoscaling
Different autoscaling models
Autoscaling an application
Autoscaling the infrastructure
Autoscaling in the cloud
Autoscaling approaches
Scaling with resource constraints
Scaling during specific time periods
Scaling based on the message queue length
Scaling based on business parameters
Predictive autoscaling
Autoscaling BrownField PSS microservices
The capabilities required for an autoscaling system
Implementing a custom life cycle manager using Spring Boot
Understanding the deployment topology
Understanding the execution flow
A walkthrough of the life cycle manager code
Running the life cycle manager
Summary
7. Logging and Monitoring Microservices
Reviewing the microservice capability model
Understanding log management challenges
A centralized logging solution
The selection of logging solutions
Cloud services
Off-the-shelf solutions
Best-of-breed integration
Log shippers
Log stream processors
Log storage
Dashboards
A custom logging implementation
Distributed tracing with Spring Cloud Sleuth
Monitoring microservices
Monitoring challenges
Monitoring tools
Monitoring microservice dependencies
Spring Cloud Hystrix for fault-tolerant microservices
Aggregating Hystrix streams with Turbine
Data analysis using data lakes
Summary
8. Containerizing Microservices with Docker
Reviewing the microservice capability model
Understanding the gaps in BrownField PSS microservices
What are containers?
The difference between VMs and containers
The benefits of containers
Microservices and containers
Introduction to Docker
The key components of Docker
The Docker daemon
The Docker client
Docker concepts
Docker images
Docker containers
The Docker registry
Dockerfile
Deploying microservices in Docker
Running RabbitMQ on Docker
Using the Docker registry
Setting up the Docker Hub
Publishing microservices to the Docker Hub
Microservices on the cloud
Installing Docker on AWS EC2
Running BrownField services on EC2
Updating the life cycle manager
The future of containerization – unikernels and hardened security
Summary
9. Managing Dockerized Microservices with Mesos and Marathon
Reviewing the microservice capability model
The missing pieces
Why cluster management is important
What does cluster management do?
Relationship with microservices
Relationship with virtualization
Cluster management solutions
Docker Swarm
Kubernetes
Apache Mesos
Nomad
Fleet
Cluster management with Mesos and Marathon
Diving deep into Mesos
The Mesos architecture
Marathon
Implementing Mesos and Marathon for BrownField microservices
Setting up AWS
Installing ZooKeeper, Mesos, and Marathon
Configuring ZooKeeper
Configuring Mesos
Running Mesos, Marathon, and ZooKeeper as services
Running the Mesos slave in the command line
Preparing BrownField PSS services
Deploying BrownField PSS services
Reviewing the deployment
A place for the life cycle manager
Rewriting the life cycle manager with Mesos and Marathon
The technology metamodel
Summary
10. The Microservices Development Life Cycle
Reviewing the microservice capability model
The new mantra of lean IT – DevOps
Reducing wastage
Automating every possible step
Value-driven delivery
Bridging development and operations
Meeting the trio – microservices, DevOps, and cloud
Cloud as the self-service infrastructure for Microservices
DevOps as the practice and process for microservices
Practice points for microservices development
Understanding business motivation and value
Changing the mindset from project to product development
Choosing a development philosophy
Design thinking
The start-up model
The Agile practice
Using the concept of Minimum Viable Product
Overcoming the legacy hotspot
Addressing challenges around databases
Establishing self-organizing teams
Building a self-service cloud
Building a microservices ecosystem
Defining a DevOps-style microservice life cycle process
Value-driven planning
Agile development
Continuous integration
Continuous testing
Continuous release
Continuous monitoring and feedback
Automating the continuous delivery pipeline
Development
Continuous integration
Automated testing
Different candidate tests for automation
Automated sanity tests
Regression testing
Automated functional testing
Automated acceptance testing
Performance testing
Real user flow simulation or journey testing
Automated security testing
Exploratory testing
A/B testing, canary testing, and blue-green deployments
Other nonfunctional tests
Testing in production
Antifragility testing
Target test environments
Continuous deployment
Monitoring and feedback
Automated configuration management
Microservices development governance, reference architectures, and libraries
Summary
3. Module 3
1. Microservices Architecture
Need for microservices
Monolithic software
Microservices in the real world
Microservice-oriented architectures
How is it better?
Shortcomings
Key design principles
Business units, no components
Smart services, dumb communication pipes
Decentralization
Technology alignment
How small is too small?
Key benefits
Resilience
Scalability
Technology heterogeneity
Replaceability
Independence
Why is replaceability important?
Easy to deploy
SOA versus microservices
Why Node.js?
API aggregation
The future of Node.js
Summary
2. Microservices in Node.js – Seneca and PM2 Alternatives
Need for Node.js
Installing Node.js, npm, Seneca, and PM2
Learning npm
Our first program – Hello World
Node.js threading model
Modular organization best practices
Javascript
SOLID design principles
Seneca – a microservices framework
Inversion of control done right
Pattern matching in Seneca
Patrun – a pattern-matching library
Reusing patterns
Writing plugins
Web server integration
Seneca as Express middleware
Data storage
PM2 – a task runner for Node.js
Single-threaded applications and exceptions
Using PM2 – the industry-standard task runner
Summary
3. From the Monolith to Microservices
First, there was the monolith
How to tackle organic growth?
How abstract is too abstract?
Then the microservices appeared
Disadvantages
Splitting the monolith
Problems splitting the monolith – it is all about the data
Organizational alignment
Summary
4. Writing Your First Microservice in Node.js
Micromerce – the big picture
Product Manager – the two-faced core
Fetching products
Fetching by category
Fetching by ID
Adding a product
Removing a product
Editing a product
Wiring everything up
Integrating with Express – how to create a REST API
The e-mailer – a common problem
How to send e-mails
Defining the interface
Setting up Mandrill
Hands on – integrating Mandrill in your microservice
The fallback strategy
The order manager
Defining the microservice – how to gather non-local data
The order manager – the code
Calling remote services
Resilience over perfection
The UI – API aggregation
Need for frontend microservice
The code
Service degradation – when the failure is not a disaster
Circuit breakers
Seneca – a simple puzzle that makes our lives easier
Seneca and promises
Debugging
Summary
5. Security and Traceability
Infrastructure logical security
SSH – encrypting the communications
Application security
Common threats – how to be up to date
Injection
Input validation
Cross-site scripting
Output encoding
Cross-site request forgery
Open redirects
Effective code reviews
Traceability
Logging
Tracing requests
Auditing
HTTP codes
1xx – informational
2xx – success codes
3xx – redirection
4xx – client errors
5xx – server errors
Why HTTP codes matter in microservices
Summary
6. Testing and Documenting Node.js Microservices
Functional testing
The pyramid of automated testing
Unit tests
Integration tests
End-to-end tests
How much testing is too much?
Testing microservices in Node.js
Chai
BDD-style interfaces
Assertions interface
Mocha
Sinon.JS – a mocking framework
Testing a real microservice
TDD – Test-driven development
Unit testing
End-to-end testing
Manual testing – the necessary evil
Building a proxy to debug our microservices
Postman
Documenting microservices
Documenting APIs with Swagger
Generating a project from the Swagger definition
Summary
7. Monitoring Microservices
Monitoring services
Monitoring using PM2 and Keymetrics
Diagnosing problems
Monitoring application exceptions
Custom metrics
Simple metric
Counter
Average calculated values
Simian Army – the active monitoring from Spotify
Throughput and performance degradation
Summary
8. Deploying Microservices
Concepts in software deployment
Continuous integration
Continuous delivery
Deployments with PM2
PM2 – ecosystems
Deploying microservices with PM2
Configuring the server
Docker – a container for software delivery
Setting up the container
Installing Docker
Choosing the image
Running the container
Installing the required software
Saving the changes
Deploying Node.js applications
Automating Docker container creation
Node.js event loop – easy to learn and hard to master
Clustering Node.js applications
Load balancing our application
Health check on NGINX
Passive health check
Active health check
Summary
A. Bibliography
Index
Search in book...
Toggle Font Controls
Playlists
Add To
Create new playlist
Name your new playlist
Playlist description (optional)
Cancel
Create playlist
Sign In
Email address
Password
Forgot Password?
Create account
Login
or
Continue with Facebook
Continue with Google
Sign Up
Full Name
Email address
Confirm Email Address
Password
Login
Create account
or
Continue with Facebook
Continue with Google
Prev
Previous Chapter
Cover
Next
Next Chapter
Microservices: Building Scalable Software
Table of Contents
Microservices: Building Scalable Software
Microservices: Building Scalable Software
Credits
Preface
What this learning path covers
What you need for this learning path
Who this learning path is for
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. Module 1
1. A Solution Approach
Evolution of µServices
Monolithic architecture overview
Limitation of monolithic architecture versus its solution with µServices
One dimension scalability
Release rollback in case of failure
Problems in adopting new technologies
Alignment with Agile practices
Ease of development – could be done better
Microservices build pipeline
Deployment using a container such as Docker
Containers
Docker
Docker's architecture
Docker image
Docker container
Deployment
Summary
2. Setting Up the Development Environment
Spring Boot configuration
Spring Boot overview
Adding Spring Boot to the rest sample
Adding a Jetty-embedded server
Sample REST program
Writing the REST controller class
@RestController
@RequestMapping
@RequestParam
@PathVariable
Making a sample REST app executable
Setting up the application build
Running the Maven tool
Executing with the Java command
REST API testing using the Postman Chrome extension
Some more positive test scenarios
Negative test scenarios
NetBeans IDE installation and setup
References
Summary
3. Domain-Driven Design
Domain-driven design fundamentals
Building blocks
Ubiquitous language
Multilayered architecture
Presentation layer
Application layer
Domain layer
Infrastructure layer
Artifacts of domain-driven design
Entities
Value objects
Frequently asked questions
Services
Aggregates
Repository
Factory
Modules
Strategic design and principles
Bounded context
Continuous integration
Context map
Shared kernel
Customer-supplier
Conformist
Anticorruption layer
Separate ways
Open host service
Distillation
Sample domain service
Entity implementation
Repository implementation
Service implementation
Summary
4. Implementing a Microservice
OTRS overview
Developing and implementing µServices
Restaurant µService
Controller class
API versioning
Service classes
Repository classes
Entity classes
Booking and user services
Registration and Discovery service (Eureka service)
Execution
Testing
References
Summary
5. Deployment and Testing
An overview of microservice architecture using Netflix OSS
Load balancing
Client-side load balancing
Server-side load balancing
Circuit breaker and monitoring
Using Hystrix's fallback methods
Monitoring
Setting up the Hystrix Dashboard
Setting up Turbine
Microservice deployment using containers
Installation and configuration
Docker Machine with 4 GB
Building Docker images with Maven
Running Docker using Maven
Integration testing with Docker
Pushing the image to a registry
Managing Docker containers
References
Summary
6. Securing Microservices
Enabling Secure Socket Layer
Authentication and authorization
OAuth 2.0
Usage of OAuth
OAuth 2.0 specification – concise details
OAuth 2.0 roles
Resource owner
Resource server
Client
Authorization server
OAuth 2.0 client registration
Client types
Confidential client type
Public client type
Web application
User agent-based application
Native application
Client identifier
Client authentication
OAuth 2.0 protocol endpoints
Authorization endpoint
Token endpoint
Redirection endpoint
OAuth 2.0 grant types
Authorization code grant
Authorization code requests and responses
Implicit grant
Implicit grant requests and responses
Resource owner password credentials grant
Client credentials grant
OAuth implementation using Spring Security
Authorization code grant
Implicit grant
Resource owner password credential grant
Client credentials grant
References
Summary
7. Consuming Services Using a Microservice Web App
AngularJS framework overview
MVC
MVVM
Modules
Providers and services
Scopes
Controllers
Filters
Directives
UI-Router
Development of OTRS features
Home page/restaurant list page
index.html
app.js
restaurants.js
restaurants.html
Search Restaurants
Restaurant details with reservation option
restaurant.html
Login page
login.html
login.js
Reservation confirmation
Setting up the web app
Summary
8. Best Practices and Common Principles
Overview and mindset
Best practices and principals
Nanoservice (not recommended), size, and monolithic
Continuous integration and deployment
System/end-to-end test automation
Self-monitoring and logging
A separate data store for each microservice
Transaction boundaries
Microservices frameworks and tools
Netflix Open Source Software (OSS)
Build – Nebula
Deployment and delivery – Spinnaker with Aminator
Service registration and discovery – Eureka
Service communication – Ribbon
Circuit breaker – Hystrix
Edge (proxy) server – Zuul
Operational monitoring – Atlas
Reliability monitoring service – Simian Army
AWS resource monitoring – Edda
On-host performance monitoring – Vector
Distributed configuration management – Archaius
Scheduler for Apache Mesos – Fenzo
Cost and cloud utilization – Ice
Other security tools – Scumblr and FIDO
Scumblr
Fully Integrated Defence Operation (FIDO)
References
Summary
9. Troubleshooting Guide
Logging and ELK stack
A brief overview
Elasticsearch
Logstash
Kibana
ELK stack setup
Installing Elasticsearch
Installing Logstash
Installing Kibana
Tips for ELK stack implementation
Use of correlation ID for service calls
Let's see how we can tackle this problem
Dependencies and versions
Cyclic dependencies and their impact
It needs to be analyzed while designing the system
Maintaining different versions
Let's explore more
References
Summary
2. Module 2
1. Demystifying Microservices
The evolution of microservices
Business demand as a catalyst for microservices evolution
Technology as a catalyst for the microservices evolution
Imperative architecture evolution
What are microservices?
Microservices – the honeycomb analogy
Principles of microservices
Single responsibility per service
Microservices are autonomous
Characteristics of microservices
Services are first-class citizens
Characteristics of services in a microservice
Microservices are lightweight
Microservices with polyglot architecture
Automation in a microservices environment
Microservices with a supporting ecosystem
Microservices are distributed and dynamic
Antifragility, fail fast, and self-healing
Microservices examples
An example of a holiday portal
A microservice-based order management system
An example of a travel agent portal
Microservices benefits
Supports polyglot architecture
Enabling experimentation and innovation
Elastically and selectively scalable
Allowing substitution
Enabling to build organic systems
Helping reducing technology debt
Allowing the coexistence of different versions
Supporting the building of self-organizing systems
Supporting event-driven architecture
Enabling DevOps
Relationship with other architecture styles
Relations with SOA
Service-oriented integration
Legacy modernization
Service-oriented application
Monolithic migration using SOA
Relations with Twelve-Factor apps
A single code base
Bundling dependencies
Externalizing configurations
Backing services are addressable
Isolation between build, release, and run
Stateless, shared nothing processes
Exposing services through port bindings
Concurrency to scale out
Disposability with minimal overhead
Development and production parity
Externalizing logs
Package admin processes
Microservice use cases
Microservices early adopters
The common theme is monolithic migrations
Summary
2. Building Microservices with Spring Boot
Setting up a development environment
Developing a RESTful service – the legacy approach
Moving from traditional web applications to microservices
Using Spring Boot to build RESTful microservices
Getting started with Spring Boot
Developing the Spring Boot microservice using the CLI
Developing the Spring Boot Java microservice using STS
Examining the POM file
Examining Application.java
Examining application.properties
Examining ApplicationTests.java
Testing the Spring Boot microservice
Developing the Spring Boot microservice using Spring Initializr – the HATEOAS example
What's next?
The Spring Boot configuration
Understanding the Spring Boot autoconfiguration
Overriding default configuration values
Changing the location of the configuration file
Reading custom properties
Using a .yaml file for configuration
Using multiple configuration profiles
Other options to read properties
Changing the default embedded web server
Implementing Spring Boot security
Securing microservices with basic security
Securing a microservice with OAuth2
Enabling cross-origin access for microservices
Implementing Spring Boot messaging
Developing a comprehensive microservice example
Spring Boot actuators
Monitoring using JConsole
Monitoring using SSH
Configuring application information
Adding a custom health module
Building custom metrics
Documenting microservices
Summary
3. Applying Microservices Concepts
Patterns and common design decisions
Establishing appropriate microservice boundaries
Autonomous functions
Size of a deployable unit
Most appropriate function or subdomain
Polyglot architecture
Selective scaling
Small, agile teams
Single responsibility
Replicability or changeability
Coupling and cohesion
Think microservice as a product
Designing communication styles
Synchronous style communication
Asynchronous style communication
How to decide which style to choose?
Orchestration of microservices
How many endpoints in a microservice?
One microservice per VM or multiple?
Rules engine – shared or embedded?
Role of BPM and workflows
Can microservices share data stores?
Setting up transaction boundaries
Altering use cases to simplify transactional requirements
Distributed transaction scenarios
Service endpoint design consideration
Contract design
Protocol selection
Message-oriented services
HTTP and REST endpoints
Optimized communication protocols
API documentations
Handling shared libraries
User interfaces in microservices
Use of API gateways in microservices
Use of ESB and iPaaS with microservices
Service versioning considerations
Design for cross origin
Handling shared reference data
Microservices and bulk operations
Microservices challenges
Data islands
Logging and monitoring
Dependency management
Organization culture
Governance challenges
Operation overheads
Testing microservices
Infrastructure provisioning
The microservices capability model
Core capabilities
Infrastructure capabilities
Supporting capabilities
Process and governance capabilities
Summary
4. Microservices Evolution – A Case Study
Reviewing the microservices capability model
Understanding the PSS application
Business process view
Functional view
Architectural view
Design view
Implementation view
Deployment view
Death of the monolith
Pain points
Stop gap fix
Retrospection
Shared data
Single database
Native queries
Stored procedures
Domain boundaries
Microservices to the rescue
The business case
Plan the evolution
Evolutionary approach
Identification of microservices boundaries
Analyze dependencies
Events as opposed to query
Events as opposed to synchronous updates
Challenge requirements
Challenge service boundaries
Final dependency graph
Prioritizing microservices for migration
Data synchronization during migration
Managing reference data
User interfaces and web applications
Session handling and security
Test strategy
Building ecosystem capabilities
Migrate modules only if required
Target architecture
Internal layering of microservices
Orchestrating microservices
Integration with other systems
Managing shared libraries
Handling exceptions
Target implementation view
Implementation projects
Running and testing the project
Summary
5. Scaling Microservices with Spring Cloud
Reviewing microservices capabilities
Reviewing BrownField's PSS implementation
What is Spring Cloud?
Spring Cloud releases
Components of Spring Cloud
Spring Cloud and Netflix OSS
Setting up the environment for BrownField PSS
Spring Cloud Config
What's next?
Setting up the Config server
Understanding the Config server URL
Accessing the Config Server from clients
Handling configuration changes
Spring Cloud Bus for propagating configuration changes
Setting up high availability for the Config server
Monitoring the Config server health
Config server for configuration files
Completing changes to use the Config server
Feign as a declarative REST client
Ribbon for load balancing
Eureka for registration and discovery
Understanding dynamic service registration and discovery
Understanding Eureka
Setting up the Eureka server
High availability for Eureka
Zuul proxy as the API gateway
Setting up Zuul
High availability of Zuul
High availability of Zuul when the client is also a Eureka client
High availability when the client is not a Eureka client
Completing Zuul for all other services
Streams for reactive microservices
Summarizing the BrownField PSS architecture
Summary
6. Autoscaling Microservices
Reviewing the microservice capability model
Scaling microservices with Spring Cloud
Understanding the concept of autoscaling
The benefits of autoscaling
Different autoscaling models
Autoscaling an application
Autoscaling the infrastructure
Autoscaling in the cloud
Autoscaling approaches
Scaling with resource constraints
Scaling during specific time periods
Scaling based on the message queue length
Scaling based on business parameters
Predictive autoscaling
Autoscaling BrownField PSS microservices
The capabilities required for an autoscaling system
Implementing a custom life cycle manager using Spring Boot
Understanding the deployment topology
Understanding the execution flow
A walkthrough of the life cycle manager code
Running the life cycle manager
Summary
7. Logging and Monitoring Microservices
Reviewing the microservice capability model
Understanding log management challenges
A centralized logging solution
The selection of logging solutions
Cloud services
Off-the-shelf solutions
Best-of-breed integration
Log shippers
Log stream processors
Log storage
Dashboards
A custom logging implementation
Distributed tracing with Spring Cloud Sleuth
Monitoring microservices
Monitoring challenges
Monitoring tools
Monitoring microservice dependencies
Spring Cloud Hystrix for fault-tolerant microservices
Aggregating Hystrix streams with Turbine
Data analysis using data lakes
Summary
8. Containerizing Microservices with Docker
Reviewing the microservice capability model
Understanding the gaps in BrownField PSS microservices
What are containers?
The difference between VMs and containers
The benefits of containers
Microservices and containers
Introduction to Docker
The key components of Docker
The Docker daemon
The Docker client
Docker concepts
Docker images
Docker containers
The Docker registry
Dockerfile
Deploying microservices in Docker
Running RabbitMQ on Docker
Using the Docker registry
Setting up the Docker Hub
Publishing microservices to the Docker Hub
Microservices on the cloud
Installing Docker on AWS EC2
Running BrownField services on EC2
Updating the life cycle manager
The future of containerization – unikernels and hardened security
Summary
9. Managing Dockerized Microservices with Mesos and Marathon
Reviewing the microservice capability model
The missing pieces
Why cluster management is important
What does cluster management do?
Relationship with microservices
Relationship with virtualization
Cluster management solutions
Docker Swarm
Kubernetes
Apache Mesos
Nomad
Fleet
Cluster management with Mesos and Marathon
Diving deep into Mesos
The Mesos architecture
Marathon
Implementing Mesos and Marathon for BrownField microservices
Setting up AWS
Installing ZooKeeper, Mesos, and Marathon
Configuring ZooKeeper
Configuring Mesos
Running Mesos, Marathon, and ZooKeeper as services
Running the Mesos slave in the command line
Preparing BrownField PSS services
Deploying BrownField PSS services
Reviewing the deployment
A place for the life cycle manager
Rewriting the life cycle manager with Mesos and Marathon
The technology metamodel
Summary
10. The Microservices Development Life Cycle
Reviewing the microservice capability model
The new mantra of lean IT – DevOps
Reducing wastage
Automating every possible step
Value-driven delivery
Bridging development and operations
Meeting the trio – microservices, DevOps, and cloud
Cloud as the self-service infrastructure for Microservices
DevOps as the practice and process for microservices
Practice points for microservices development
Understanding business motivation and value
Changing the mindset from project to product development
Choosing a development philosophy
Design thinking
The start-up model
The Agile practice
Using the concept of Minimum Viable Product
Overcoming the legacy hotspot
Addressing challenges around databases
Establishing self-organizing teams
Building a self-service cloud
Building a microservices ecosystem
Defining a DevOps-style microservice life cycle process
Value-driven planning
Agile development
Continuous integration
Continuous testing
Continuous release
Continuous monitoring and feedback
Automating the continuous delivery pipeline
Development
Continuous integration
Automated testing
Different candidate tests for automation
Automated sanity tests
Regression testing
Automated functional testing
Automated acceptance testing
Performance testing
Real user flow simulation or journey testing
Automated security testing
Exploratory testing
A/B testing, canary testing, and blue-green deployments
Other nonfunctional tests
Testing in production
Antifragility testing
Target test environments
Continuous deployment
Monitoring and feedback
Automated configuration management
Microservices development governance, reference architectures, and libraries
Summary
3. Module 3
1. Microservices Architecture
Need for microservices
Monolithic software
Microservices in the real world
Microservice-oriented architectures
How is it better?
Shortcomings
Key design principles
Business units, no components
Smart services, dumb communication pipes
Decentralization
Technology alignment
How small is too small?
Key benefits
Resilience
Scalability
Technology heterogeneity
Replaceability
Independence
Why is replaceability important?
Easy to deploy
SOA versus microservices
Why Node.js?
API aggregation
The future of Node.js
Summary
2. Microservices in Node.js – Seneca and PM2 Alternatives
Need for Node.js
Installing Node.js, npm, Seneca, and PM2
Learning npm
Our first program – Hello World
Node.js threading model
Modular organization best practices
Javascript
SOLID design principles
Seneca – a microservices framework
Inversion of control done right
Pattern matching in Seneca
Patrun – a pattern-matching library
Reusing patterns
Writing plugins
Web server integration
Seneca as Express middleware
Data storage
PM2 – a task runner for Node.js
Single-threaded applications and exceptions
Using PM2 – the industry-standard task runner
Summary
3. From the Monolith to Microservices
First, there was the monolith
How to tackle organic growth?
How abstract is too abstract?
Then the microservices appeared
Disadvantages
Splitting the monolith
Problems splitting the monolith – it is all about the data
Organizational alignment
Summary
4. Writing Your First Microservice in Node.js
Micromerce – the big picture
Product Manager – the two-faced core
Fetching products
Fetching by category
Fetching by ID
Adding a product
Removing a product
Editing a product
Wiring everything up
Integrating with Express – how to create a REST API
The e-mailer – a common problem
How to send e-mails
Defining the interface
Setting up Mandrill
Hands on – integrating Mandrill in your microservice
The fallback strategy
The order manager
Defining the microservice – how to gather non-local data
The order manager – the code
Calling remote services
Resilience over perfection
The UI – API aggregation
Need for frontend microservice
The code
Service degradation – when the failure is not a disaster
Circuit breakers
Seneca – a simple puzzle that makes our lives easier
Seneca and promises
Debugging
Summary
5. Security and Traceability
Infrastructure logical security
SSH – encrypting the communications
Application security
Common threats – how to be up to date
Injection
Input validation
Cross-site scripting
Output encoding
Cross-site request forgery
Open redirects
Effective code reviews
Traceability
Logging
Tracing requests
Auditing
HTTP codes
1xx – informational
2xx – success codes
3xx – redirection
4xx – client errors
5xx – server errors
Why HTTP codes matter in microservices
Summary
6. Testing and Documenting Node.js Microservices
Functional testing
The pyramid of automated testing
Unit tests
Integration tests
End-to-end tests
How much testing is too much?
Testing microservices in Node.js
Chai
BDD-style interfaces
Assertions interface
Mocha
Sinon.JS – a mocking framework
Testing a real microservice
TDD – Test-driven development
Unit testing
End-to-end testing
Manual testing – the necessary evil
Building a proxy to debug our microservices
Postman
Documenting microservices
Documenting APIs with Swagger
Generating a project from the Swagger definition
Summary
7. Monitoring Microservices
Monitoring services
Monitoring using PM2 and Keymetrics
Diagnosing problems
Monitoring application exceptions
Custom metrics
Simple metric
Counter
Average calculated values
Simian Army – the active monitoring from Spotify
Throughput and performance degradation
Summary
8. Deploying Microservices
Concepts in software deployment
Continuous integration
Continuous delivery
Deployments with PM2
PM2 – ecosystems
Deploying microservices with PM2
Configuring the server
Docker – a container for software delivery
Setting up the container
Installing Docker
Choosing the image
Running the container
Installing the required software
Saving the changes
Deploying Node.js applications
Automating Docker container creation
Node.js event loop – easy to learn and hard to master
Clustering Node.js applications
Load balancing our application
Health check on NGINX
Passive health check
Active health check
Summary
A. Bibliography
Index
Add Highlight
No Comment
..................Content has been hidden....................
You can't read the all page of ebook, please click
here
login for view all page.
Day Mode
Cloud Mode
Night Mode
Reset