TypeScript Microservices
Parth Ghiya更新时间:2021-06-25 21:49:45
最新章节:Leave a review - let other readers know what you think封面
版权信息
Packt Upsell
Why subscribe?
PacktPub.com
Contributors
About the author
About the reviewer
Packt is searching for authors like you
Preface
Who this book is for
What this book covers
To get the most out of this book
Download the example code files
Download the color images
Conventions used
Get in touch
Reviews
Debunking Microservices
Debunking microservices
Rise of microservices
Wide selection of languages as per demand
Easy handling of ownership
Frequent deployments
Self-sustaining development units
What are microservices?
Principles and characteristics
No monolithic modules
Dumb communication pipes
Decentralization or self-governance
Service contracts and statelessness
Lightweight
Polyglot
Good parts of microservices
Self-dependent teams
Graceful degradation of services
Supports polyglot architecture and DevOps
Event-driven architecture
Bad and challenging parts of microservices
Organization and orchestration
Platform
Testing
Service discovery
Microservice example
Key considerations while adopting microservices
Service degradation
Proper change governance
Health checks load balancing and efficient gateway routing
Self-curing
Cache for failover
Retry until
Microservice FAQs
Twelve-factor application of microservices
Microservices in the current world
Netflix
Walmart
Spotify
Zalando
Microservice design aspects
Communication between microservices
Remote Procedure Invocation (RPI)
Messaging and message bus
Protobufs
Service discovery
Service registry for service-service communication
Server-side discovery
Client-side discovery
Registration patterns – self-registration
Data management
Database per service
Sharing concerns
Externalized configuration
Observability
Log aggregation
Distributed tracing
Microservice design patterns
Asynchronous messaging microservice design pattern
Backend for frontends
Gateway aggregation and offloading
Proxy routing and throttling
Ambassador and sidecar pattern
Anti-corruption microservice design pattern
Bulkhead design pattern
Circuit breaker
Strangler pattern
Summary
Gearing up for the Journey
Setting up primary environment
Visual Studio Code (VS Code)
PM2
NGINX
Docker
Primer to TypeScript
Understanding tsconfig.json
compilerOptions
include and exclude
extends
Understanding types
Installing types from DefinitelyTyped
Writing your own types
Using the dts-gen tool
Writing your own *.d.ts file
Debugging
Primer to Node.js
Event Loop
Understanding Event Loop
Node.js clusters and multithreading
Async/await
Retrying failed requests
Multiple requests in parallel
Streams
Writing your first Hello World microservice
Summary
Exploring Reactive Programming
Introduction to reactive programming
Why should I consider adopting reactive programming?
Reactive Manifesto
Responsive systems
Resilient to errors
Elastic scalable
Message-driven
Major building blocks and concerns
Observable streams
Subscription
emit and map
Operator
Backpressure strategy
Currying functions
When to react and when not to react (orchestrate)
Orchestration
Benefits
Disadvantages
Reactive approach
Benefits
Disadvantages
React outside orchestrate inside
Reactive coordinator to drive the flow
Synopsis
When a pure reactive approach is a perfect fit
When pure orchestration is a perfect fit
When react outside orchestrate inside is a perfect fit
When introducing a reactive coordinator is the perfect fit
Being reactive in Node.js
Rx.js
Bacon.js
HighLand.js
Key takeaways
Summary
Beginning Your Microservice Journey
Overview of shopping cart microservices
Business process overview
Functional view
Deployment view
Architecture design of our system
Different microservices
Cache microservice
Service registry and discovery
Registrator
Logger
Gateway
Design aspects involved
Microservice efficiency model
Core functionalities
Supporting efficiencies
Infrastructure role
Governance
Implementation plan for shopping cart microservices
What to do when the scope is not clear
Schema design and database selection
How to segregate data between microservices
Postulate 1 – data ownership should be regulated via business capabilities
Postulate 2 – replicate the database for speed and robustness
How to choose a data store for your microservice
Design of product microservices
Microservice predevelopment aspects
HTTP code
1xx – informational
2xx – success
3xx – redirections
4xx – client errors
5xx – server errors
Why HTTP code is vital in microservices?
Auditing via logs
PM2 process manager
Tracing requests
Developing some microservices for a shopping cart
Itinerary
Development setup and prerequisite modules
Repository pattern
Configuring application properties
Custom health module
Dependency injection and inversion of control
Inversify
Typedi
TypeORM
Application directory configurations
src/data-layer
src/business-layer
src/service-layer
src/middleware
Configuration files
Processing data
Ready to serve (package.json and Docker)
package.json
Docker
Synopsis
Microservice design best practices
Setting up proper microservice scope
Self-governing functions
Polyglot architecture
Size of independent deployable component
Distributing and scaling services whenever required
Being Agile
Single business capability handler
Adapting to shifting needs
Handling dependencies and coupling
Deciding the number of endpoints in a microservice
Communication styles between microservices
Specifying and testing the microservices contract
Number of microservices in a container
Data sources and rule engine among microservices
Summary
Understanding API Gateway
Debunking API Gateway
Concerns API Gateway handles
Security
Dumb gateways
Transformation and orchestration
Monitoring alerting and high availability
Caching and error handling
Service registry and discovery
Circuit breakers
Versioning and dependency resolution
API Gateway design patterns and aspects
Circuit breakers and its role
Need for gateway in our shopping cart microservices
Handle performance and scalability
Reactive programming to up the odds
Invoking services
Discovering services
Handling partial service failures
Design considerations
Available API Gateways options
HTTP proxy and Express Gateway
Zuul and Eureka
API Gateway versus reverse proxy NGINX
RabbitMQ
Designing our gateway for shopping cart microservices
What are we going to use?
Summary
Service Registry and Discovery
Introduction to the service registry
What why and how of service registry and discovery
The why of service registry and discovery
How service registry and discovery?
Service registration
Service resolution
The what of service registry and discovery
Maintaining service registry
Timely health checks
Service discovery patterns
Client-side discovery pattern
Server-side discovery pattern
Service registry patterns
Self-registration pattern
Third-party registration pattern
Service registry and discovery options
Eureka
Setting up the Eureka server
Registering with Eureka server
Discovering with Eureka server
Key points for Eureka
Consul
Setting up the Consul server
Talking with Consul server
Registering a service instance
Sending heartbeats and doing a health check
Deregistering an application
Subscribing to updates
Key points for Consul
Registrator
Key points for Registrator
How to choose service registry and discovery
If you select Consul
If you select Eureka
Summary
Service State and Interservice Communication
Core concepts – state communication and dependencies
Microservice state
Interservice communication
Commands
Queries
Events
Exchanging data formats
Text-based message formats
Binary message formats
Dependencies
Communication styles
NextGen communication styles
HTTP/2
gRPC with Apache Thrift
Versioning microservices and failure handling
Versioning 101
When a developer's nightmare comes true
Client resiliency patterns
Bulkhead and retry pattern
Client-side load balancing or queue-based load leveling pattern
Circuit breaker pattern
The fallback and compensating transaction pattern
Case Study – The NetFlix Stack
Part A – Zuul and Polyglot Environment
Part B – Zuul Load balancing and failure resiliency
Message queues and brokers
Introduction to pub/sub pattern
Sharing dependencies
The problem and solution
Getting started with bit
The problem of shared data
Cache
Blessing and curse of caching
Introduction to Redis
Setting up our distributed caching using redis
Summary
Testing Debugging and Documenting
Testing
What and how to test
The testing pyramid – what to test?
System tests
Service tests
Contract tests
Unit tests
Hands-on testing
Our libraries and test tool types
Chai
Mocha
Ava
Sinon
Istanbul
Contract tests using Pact.js
What is consumer-driven contract testing?
Introduction to Pact.js
Bonus (containerizing pact broker)
Revisiting testing key points
Debugging
Building a proxy in between to debug our microservices
Profiling process
Dumping heap
CPU profiling
Live Debugging/Remote Debugging
Key points for debugging
Documenting
Need of Documentation
Swagger 101
Swagger Editor and Descriptor
Key points for Swagger and Descriptor
Swagger Editor
Swagger Codegen
Swagger UI
Swagger Inspector
Possible strategies to use Swagger
Top-down or design-first Approach
Bottom-up approach
Generating a project from a Swagger definition
Summary
Deployment Logging and Monitoring
Deployment
Deciding release plan
Deployment options
DevOps 101
Containers
Containers versus Virtual Machine (VMs)
Docker and the world of containers
Docker components
Docker concepts
Docker command reference
Setting up Docker with NGINX Node.js and MongoDB
WebHooks in our build pipeline
Serverless architecture
Logging
Logging best practices
Centralizing and externalizing log storage
Structured data in logs
Identifiers via correlational IDs
Log levels and logging mechanisms
Searchable logs
Centralized custom logging solution implementation
Setting up our environment
Distributed tracing in Node.js
Monitoring
Monitoring 101
Monitoring challenges
When to alert and when not to alert?
Monitoring tools
PM2 and keymetrics
Keymetrics to monitor application exceptions and runtime problems
Adding custom metrics
Simple metrics
Counter metric
Meter
Prometheus and Grafana
Production-ready microservice criteria
Summary
Hardening Your Application
Questions you should be asking while applying security
Core application/core microservice
Middleware
API Gateway
Team and operational activities
Security best practices for individual services/applications
Checking for known security vulnerabilities
Auditjs
Snyk.io
Preventing brute force attacks or flooding by adding rate limiters
Protecting against evil regular expressions
Blocking cross-site request forgeries
Tightening session cookies and effective session management
Adding helmet to configure security headers
Avoiding parameter pollution
Securing transmission
Preventing command injection/SQL injection
TSLint/static code analyzers
Security best practices for containers
Securing container builds and standardizing deployments
Securing containers at runtime
Security checklist
Service necessities
Service interactions
Development phase
Deployment
Operations
Scalability
AWS Load Balancer
Benefits of using a load balancer
Fault tolerance
High availability
Flexibility
Security
Health check parameters
Unhealthy threshold
Healthy threshold
Timeout
Health check protocol
Health check port
Interval
Configuring a load balancer
Autoscaling – practical hands on with AWS
Creating the launch configuration
Creating an autoscaling group and configuring it with autoscaling policies
Creating an application load balancer and adding a target group
Time to test
Scaling with Kubernetes
What problem does Kubernetes solve?
Kubernetes concepts
Summary
Other Books You May Enjoy
Leave a review - let other readers know what you think
更新时间:2021-06-25 21:49:45