Download Microservices for the Enterprise: Designing, Developing, and Deploying PDF

TitleMicroservices for the Enterprise: Designing, Developing, and Deploying
LanguageEnglish
File Size14.1 MB
Total Pages434
Table of Contents
                            Table of Contents
About the Authors
About the Technical Reviewer
Acknowledgments
Introduction
Chapter 1: The Case for Microservices
	From a Monolith to a Microservices Architecture
		Monolithic Applications
		SOA and ESB
		APIs
	What Is a Microservice?
		Business Capability Oriented
		Autonomous: Develop, Deploy, and Scale Independently
		No Central ESB: Smart Endpoints and Dumb Pipes
		Failure Tolerance
		Decentralized Data Management
		Service Governance
		Observability
	Microservices: Benefits and Liabilities
		Benefits
			Agile and Rapid Development of Business Functionalities
			Replaceability
			Failure Isolation and Predictability
			Agile Deployment and Scalability
			Align with Organizational Structure
		Liabilities
			Inter-Service Communication
			Service Governance
			Heavily Depends on Deployment Methodologies
			Complexity of Distributed Data and Transaction Management
	How and When to Use Microservices
	Summary
Chapter 2: Designing Microservices
	Domain-Driven Design
		Bounded Context
		Context Map
		Relational Patterns
			Anti-Corruption Layer
			Shared Kernel
			Conformist
			Customer/Supplier
			Partnership
			Published Language
			Open Host Service
			Separate Ways
			Big Ball of Mud
	Design Principles
		High Cohesion And Loose Coupling
		Resilience
			Timeouts
			Circuit Breaker
			Bulkheads
			Steady State
			Fail Fast
			Let It Crash
			Handshaking
			Test Harness
			Shed Load
		Observability
		Automation
	12-Factor App
		Codebase
		Dependencies
		Configuration
		Backing Services
		Build, Release, Run
		Processes
			Shared Nothing Architecture
		Port Binding
		Concurrency
		Disposability
		Dev/Prod Parity
		Logs
		Admin Processes
		Beyond the 12 Factor App
			API First
			Telemetry
			Security
	Summary
Chapter 3: Inter-Service Communication
	Fundamentals of Microservices Communication
	Synchronous Communication
		REST
			Richardson Maturity Model
		gRPC
			A Glimpse of HTTP2
			Inter-Service Communication with gRPC
			Error Handling with gRPC
		GraphQL
		WebSockets
		Thrift
	Asynchronous Communication
		Single Receiver
			AMQP
		Multiple Receivers
			Kafka
			Other Asynchronous Communication Protocols
	Synchronous versus Asynchronous Communication
	Message Formats/Types
		JSON and XML
		Protocol Buffers
		Avro
	Service Definitions and Contracts
	Summary
Chapter 4: Developing Services
	Developer Tooling and Frameworks
		Netflix OSS
			Nebula
			Spinnaker
			Eureka
			Archaius
			Ribbon
			Hystrix
			Zuul
		Spring Boot
		Istio
		Dropwizard
		Vert.x
		Lagom
	Getting Started with Spring Boot
		Hello World!
		Spring Boot Actuator
		Configuration Server
		Consuming Configurations
		Service-to-Service Communication
	Getting Started with gRPC
		Building the gRPC Service
		Building the gRPC Client
	Event-Driven Microservices with Kafka
		Setting Up a Kafka Message Broker
		Building Publisher (Event Source)
		Building Consumer (Event Sink)
	Building GraphQL Services
	Summary
Chapter 5: Data Management
	Monolithic Applications and Shared Databases
	A Database per Microservice
	Sharing Data Between Microservices
		Eliminating Shared Tables
		Shared Data
			Synchronous Lookups
			Using Asynchronous Events
			Shared Static Data
		Data Composition
			Composite Services or Client-Side Mashups
			Joins with Materialize View Using Asynchronous Events
	Transactions with Microservices
		Avoiding Distributed Transactions with Two-Phase Commit
		Publishing Events Using Local Transactions
		Database Log Mining
		Event Sourcing
		Saga
			Saga Log
			Saga Execution Coordinator (SEC)
			Executing a Distributed Saga
	Polyglot Persistence
	Caching
	Summary
Chapter 6: Microservices Governance
	Why Microservices Governance?
	Aspects of Microservices Governance
		Service Definition
		Service Registry and Discovery
		Service Lifecycle Management
		Quality of Service (QoS)
		Service Observability
	Implementing Microservice Governance
		Service Registry and Discovery
		Development Lifecycle Management
		API Management/API Gateway
		Observability
	Service Registry and Discovery
		Consul
			Registering a Service
			Discovering a Service
		Eureka
			Using Eureka with Spring Boot
		Etcd
		Service Discovery with Kubernetes
	Summary
Chapter 7: Integrating Microservices
	Why We Have to Integrate Microservices
	Smart Endpoints and Dumb Pipes
	Anti-Patterns of Microservice Integration
		Monolithic API Gateway for Integrating Microservices
		Integrating Microservice with an ESB
		Using Homogeneous Technologies to Build all Your Microservices
	Organizing Microservices
		Core Services
		Integration Services
		API Services
	Microservices Integration Patterns
		Active Composition or Orchestration
		Reactive Composition or Choreography
		Hybrid of Active and Reactive Composition
		Anti-Corruption Layer
		Strangler Façade
	Key Requirements of Integration Services
		Network Communication Abstractions
		Resiliency Patterns
			Timeout
			Circuit Breaker
			Fail Fast
			Bulkhead
			Load Balancing and Failover
		Active or Reactive Composition
		Data Formats
		Container-Native and DevOps Ready
		Governance of Integration Services
		Stateless, Stateful, or Long-Running Services
	Technologies for Building Integration Services
		Spring Boot
			RESTful Services
			Network Communication Abstractions
				HTTP
				JMS
				Databases/JDBC
				Web APIs: Twitter
			Resiliency Patterns
			Data Formats
			Observability
		Dropwizard
		Apache Camel and Spring Integration
		Vert.x
		Akka
		Node, Go, Rust, and Python
		Ballerina
			Network-Aware Abstractions
			Resilient and Safe Integration
			Data Formats
			Observablity
		Workflow Engine Solutions
	Inception of the Service Mesh
	Summary
Chapter 8: Deploying and Running Microservices
	Containers and Microservices
		Introduction to Docker
			Installing Docker
			Docker Architecture
			Docker Images
			Docker Registry
			Containers
		Deploying Microservices with Docker
			Creating a Docker Image with a Microservice
			Running a Microservice as a Docker Container
			Publishing a Docker Image to the Docker Hub
		Docker Compose
			Building a Docker Image for Inventory Microservice
			Launching the Application with Docker Compose
			Testing the Application with cURL
			How Does the Communication Happen Between Containers?
	Container Orchestration
		Introduction to Kubernetes
			Kubernetes Architecture
			Installing Kubectl
			Installing Minikube
			Test the Kubernetes Setup
		Kubernetes Core Concepts
			Pod
			Creating a Pod
			ReplicaSet
			Service
			Deployment
		Deploying Microservices in a Kubernetes Environment
			Creating a Pod with a YAML File
			Creating a Service with a YAML File
			Testing the Pod with cURL
			How Does Communication Happen Between Containers in the Same Pod?
			How Does Communication Happen Between Containers in Different Pods?
			Deployments and Replica Sets
			Scaling a Deployment
			Autoscaling a Deployment
			Helm: Package Management with Kubernetes
	Microservices Deployment Patterns
		Multiple Services per Host
		Service per Host
		Service per Virtual Machine
		Service per Container
	Container-Native Microservice Frameworks
		Metaparticle
			Containerizing a Spring Boot Service
			Spring Boot and Docker Integration
			Ballerina: Docker and Kubernetes Integration
	Continuous Integration, Delivery, and Deployment
		Continuous Integration
		Continuous Delivery
		Continuous Deployment
			Blue-Green Deployment
			Canary Releases
			A/B Testing
	Summary
Chapter 9: Service Mesh
	Why Service Mesh?
	What Is a Service Mesh?
		Business Logic
		Primitive Network Functions
		Application Network Functions
		Control Plane
	Functionalities of a Service Mesh
		Resiliency for Inter-Service Communications
		Service Discovery
		Routing
		Observability
		Security
		Deployment
		Inter-Service Communication Protocols
	Istio
		Istio Architecture
			Istio Proxy
			Mixer
			Pilot
			Citadel
		Using Istio
			Running Your Services with Istio
			Traffic Management with Istio
			Request Routing
			Resiliency
			Fault Injection
			Policy Enforcement
			Observability
			Security
	Linkerd
	Should We Use Service Mesh?
		Pros
		Cons
	Summary
Chapter 10: APIs, Events, and Streams
	APIs and API Management
		API Publisher/API Lifecycle Manager
		API Gateway
			API Micro-Gateway
		API Store/Developer Portal
		API Analytics/Observability
		API QoS
		API Monetization
		API Definition with OpenAPI
		A Query Language for Your APIs: GraphQL
		API Management and Service Mesh
		Implementing API Management
	Events
		Event Notifications
		Event-Carried State Transfer
		Event Sourcing
		Command Query Responsibility Segregation (CQRS)
	Streams
		Stream Processing
			Programmatic Stream Processing
			Streaming SQL
	A Microservices Architecture with APIs, Events, and Streams
	Summary
Chapter 11: Microservices Security Fundamentals
	Monolith versus Microservices
	Securing Service-to-Service Communication
		JSON Web Token (JWT)
			Propagating Trust and User Identity
		Transport Layer Security (TLS) Mutual Authentication
			Certificate Revocation
			Short-Lived Certificates
	The Edge Security
		OAuth 2.0
	Access Control
		XACML (eXtensible Access Control Markup Language)
		Embedded PDP
	Security Sidecar
	Summary
Chapter 12: Securing Microservices
	Securing a Microservice with OAuth 2.0
		Enable Transport Layer Security (TLS)
		Setting Up an OAuth 2.0 Authorization Server
		Protecting a Microservice with OAuth 2.0
	Securing a Microservice with Self-Contained Access Tokens (JWT)
		Setting Up an Authorization Server to Issue JWT
		Protecting a Microservice with JWT
	Controlling Access to a Microservice
		Scope-Based Access Control
		Role-Based Access Control
	Securing Service-to-Service Communication
		Service-to-Service Communication Secured with JWT
		Service-to-Service Communication Secured with TLS Mutual Authentication
	Securing Actuator Endpoints
	Summary
Chapter 13: Observability
	Three Pillars of Observability
	Distributed Tracing with Spring Cloud Sleuth
		Spring Cloud Sleuth
		Engaging Spring Cloud Sleuth with Spring Boot Microservices
		Tracing Messages Between Multiple Microservices with Spring Cloud Sleuth
	Data Visualization and Correlation with Zipkin
		Event-Driven Log Aggregation Architecture
	Introduction to Open Tracing
		Distributed Tracing with Open Tracing Using Spring Boot Microservices and Zipkin
		Distributed Tracing with Open Tracing Using Spring Boot Microservices and Jaeger
	Metrics with Prometheus
		Exposing Metrics from the Spring Boot Microservice
		Setting Up Prometheus
		Building Graphs with Prometheus
	Analytics and Monitoring with Grafana
		Building a Dashboard with Grafana
		Creating Alerts with Grafana
	Using Fluentd Log Collector with Docker
		Starting Fluentd as a Docker Container
		Publishing Logs to Fluentd from a Microservice Running in a Docker Container
		How It Works
		Using Fluentd in a Microservices Deployment
	Summary
Index
                        
Document Text Contents
Page 1

Microservices
for the
Enterprise

Designing, Developing, and Deploying

Kasun Indrasiri
Prabath Siriwardena

Page 2

Microservices for the
Enterprise

Designing, Developing, and
Deploying

Kasun Indrasiri
Prabath Siriwardena

Page 217

202

We create an HTTP server and a router. Once we’ve done that, we create a simple

route with no matching criteria so it will match all requests that arrive on the server.

We then specify a handler for that route. That handler will be called for all the requests

that arrive on the server. You can further add routing logic, which captures the path

parameters and HTTP methods etc. (You can try this example from our examples in

ch07/sample09.)

Route route = router.route(HttpMethod.POST, "/catalogue/products/:productty

pe/:productid/");

route.handler(routingContext -> {

String productType = routingContext.request().getParam(“producttype”);

String productID = routingContext.request().getParam("productid");

// Do something with them...

});

The client-side code is also trivial as Vet.x provides quite a few abstractions to interact

with the clients. (You can try this example from our examples in ch07/sample10.)

WebClient client = WebClient.create(vertx);

client

.post(8080, "myserver.mycompany.com", "/some-uri")

.sendJsonObject(new JsonObject()

.put("firstName", "Dale")

.put("lastName", "Cooper"), ar -> {

if (ar.succeeded()) {

// Ok

}

});

Vert.x-Web API Contract brings two features to help you to develop your APIs, HTTP

Request validation, and OpenAPI 3 support with automatic requests validation. Vert.x

also provides different asynchronous clients for accessing various datastores from your

microservice. (You can try this example from our examples in ch07/sample11.)

Chapter 7 IntegratIng MICroservICes

Page 218

203

SQLClient client = JDBCClient.createNonShared(vertx, config);

client.getConnection(res -> {

if (res.succeeded()) {

SQLConnection connection = res.result();

connection.query("SELECT * FROM some_table", res2 -> {

if (res2.succeeded()) {

ResultSet rs = res2.result();

// Do something with results

connection.close();

}

});

} else {

// Failed to get connection - deal with it

}

});

Similarly, we can also connect your services with Redis, MongoDB, MySQL,

and many more using Vet.x. For microservices integration, resilient inter-service

communication capabilities such as circuit breaker are also included as part of Vert.x.

(You can try this example from our examples in ch07/sample12.)

CircuitBreaker breaker = CircuitBreaker.create("my-circuit-breaker", vertx,

new CircuitBreakerOptions().setMaxFailures(5).setTimeout(2000)

);

breaker.<String>execute(future -> {

vertx.createHttpClient().getNow(8080, "localhost", "/", response -> {

if (response.statusCode() != 200) {

future.fail("HTTP error");

} else {

response

.exceptionHandler(future::fail)

.bodyHandler(buffer -> {

future.complete(buffer.toString());

});

}

});

Chapter 7 IntegratIng MICroservICes

Page 433

421

configuration server, 104–106
data formats, 197
definition, 94
git command, 98
GraphQL, 122–123
Hello World!, 99–102
microservices implementation, 191
network communication abstractions

databases/JDBC, 195
HTTP, 193–194
JMS, 194–195
Twitter, 195–196

OAuth 2.0 (see OAuth 2.0)
observability, 198
resiliency patterns, 196–197
RESTful services, 192–193
service-to-service

communication, 108–111
setting up Java/Maven, 98
Spring Cloud, 94
Spring Cloud Sleuth, 377–380
Spring Initializer, 99

Spring Cloud Sleuth
distributed tracing, 376
multiple microservices, 380–381
spans

Order Processing, 375–376
tree-like structure, 376–377

Spring Boot, 377–380
Spring Initializer, 99
Spring Integration, 199–201
Spring Tool Suite (STS), 99
Steady state pattern, 45–46
Strangler façade, 181
Streaming

definition, 308
microservices architecture, 310–311

processors, 309
SQL, 310

Swagger, 59, 152, 300

T, U
Telemetry, 60
Test harness, 47–48
Thrift, 76
Timeouts, 43
Transaction manager, 138
Transactions

ACID properties, 138
database log mining, 141–142
distributed, two-phase

commit, 138–139
event sourcing, 142–143
local, publishing events, 140–141
monolithic applications, 138
Saga (see Saga)

Transactions Per Second (TPS), 11
Transport layer security (TLS)

Citadel, 274
enable, 348–350
handshaking, 47
mutual authentication

certificate revocation, 325–326
client and server, 324
JWT-based approach, 325
service-to-service

communication, 367–369
short-lived certificates, 326–327

Transport level security (TLS), 270

V
Vert.x, 96–97, 201–204

Index

Page 434

422

W, X, Y
WebSockets, 75–76

Z
Zeebe, 215
Zipkin

application.properties file, 382
dependency graph, 385

event-driven log aggregation
architecture, 385–386

Order Processing and inventory
microservices, 382

publish logs, 381–383
setting up, 381
tracing information, 383–385
web-based console, 381, 384

Zuul, 93

Index

Similer Documents