Cover....1
Title Page....2
Copyright and Credits....3
Contributors....4
Table of Contents....6
Preface....14
Part 1: Understanding Microservices and Node.js....20
Chapter 1: Introducing Microservices....22
Introduction to the microservices and decentralized architecture concepts....23
Microservices architecture....23
Decentralized architecture....25
Service boundaries and loose coupling....27
Service boundaries....27
Loose coupling....28
Independent development and deployment and polyglot architecture....29
Independent development and deployment....30
Polyglot architecture....31
Scalability and resilience and independent data management....32
Scalability and resilience....32
Independent data management....34
APIs and communication and CI....35
APIs and communication....36
CI....37
Summary....38
Quiz time....39
Chapter 2: Exploring the Core Principles of Microservices....40
Overview of the core principles of microservices....41
Understanding the fundamentals and identifying business capabilities....43
Defining service contracts and decentralized decision making....44
Service contracts in microservices....44
Decentralized decision making in microservices....46
Prioritizing autonomy and ownership and designing for resilience....47
Prioritizing autonomy and ownership....47
Designing for resilience....49
Implementing communication strategies and ensuring scalability....50
Implementing communication strategies....51
Ensuring scalability....51
Implementing observability and continuously learning and improving....54
Implementing observability....54
Continuous learning and improving....54
Summary....56
Quiz time....56
Chapter 3: Understanding Node.js Fundamentals: Building Blocks and Key Concepts....58
Asynchronous and non-blocking communication and event-driven architecture....59
Asynchronous and non-blocking communication....59
Event-driven architecture....60
The JavaScript ecosystem and server-side development....61
The JavaScript ecosystem....62
Server-side development with Node.js....63
Command-line applications and scalability and performance....64
Command-line applications....65
Scalability and performance....66
Cross-platform compatibility and community and support....67
Cross-platform compatibility....67
Community and support....68
Microservices and serverless architectures and their integration through APIs....69
What is microservices architecture?....69
What is a serverless architecture?....71
Integration through APIs....72
Integration in microservices and serverless architectures....73
Summary....73
Quiz time....73
Chapter 4: Leveraging the JavaScript and Node.js Ecosystem for Microservices Development....74
Vast package management and developer productivity....75
Vast package management....75
Developer productivity....76
Community support and collaboration, and rapid innovation and updates....78
Community support and collaboration....78
Rapid innovation and updates....79
Versatility and full stack development, and cross-platform compatibility....80
Versatility and full stack development....81
Cross-platform compatibility....82
Integration and interoperability and support for modern web standards....83
Integration and interoperability....83
Support for modern web standards....84
Enterprise adoption and industry maturity and ecosystem growth and innovation....85
Enterprise adoption and industry maturity....85
What is ecosystem growth and innovation?....86
Summary....88
Quiz time....88
Part 2: Building and Integrating Microservices with Node.js....90
Chapter 5: Knowing the Infrastructure of Microservices in Node.js....92
Service discovery and API gateways....93
Service discovery....93
API gateways....94
Load balancing and service orchestration....97
Load balancing....97
Service orchestration....99
Containerization and orchestration and centralized logging and monitoring....101
Containerization and orchestration....101
Centralized logging and monitoring....102
Distributed tracing and event-driven communication....104
Distributed tracing....104
Event-driven communication....105
Database integration and continuous integration and deployment....105
Database integration....105
CI/CD....107
Summary....108
Quiz time....109
Chapter 6: Designing Microservices Architecture in Node.js....110
Things to consider before creating your microservice....110
Communication protocol and design APIs....113
Communication protocol....113
API design....114
Decentralized data management and data consistency....117
Authentication and authorization and error handling and fault tolerance....119
Authentication and authorization....119
Error handling and fault tolerance....120
Monitoring and tracing requests and containerization technologies....121
Monitoring and tracing requests....121
Containerization technologies....123
Summary....125
Quiz time....125
Chapter 7: Integrating Microservices in Node.js Applications....126
Synchronous HTTP/REST communication and asynchronous messaging....126
Synchronous HTTP/REST communication....127
Asynchronous messaging....129
EDA and API gateways....131
EDA....131
API gateways....132
Service mesh and caching....133
Service mesh....133
Caching....135
Distributed tracing and database integration....136
Distributed tracing....136
Database integration....137
Monitoring and observability and error handling and resilience....139
Monitoring and observability....139
Error handling and resilience....141
Summary....143
Quiz time....143
Chapter 8: Debugging Microservices in Node.js....144
Logging and debugging tools....144
Logging in microservices....144
Debugging tools....146
Debugging in containers and error handling....148
Debugging in containers....149
Error handling....150
Unit testing and remote debugging....151
Unit testing....151
Remote debugging....152
Instrumentation and tracing and environment and configuration....154
Instrumentation and tracing....154
Environment and configuration....155
Reproducing and isolating issues and debugging tools and libraries....156
Reproduce and isolate issues....156
Debugging tools and libraries....157
Summary....159
Quiz time....159
Part 3: Data Management in Microservices Using Node.js....160
Chapter 9: Database Manipulation in Microservices with Node.js....162
Choosing the right database and database connections....163
Choosing the right database....163
Database connections in microservices....165
Data models and schemas and CRUD operations....166
Data models and schemas....166
CRUD operations....167
Transactions and data validation....168
Transactions in microservices....168
Data validation and sanitization....170
Error handling and optimizations....172
Error handling in microservices....172
Optimizations in microservices....174
Testing....175
Summary....177
Quiz time....178
Chapter 10: API Communication and Data Contracts in Microservices....180
Defining API contracts and RESTful API design....180
Defining API contracts....181
RESTful API design....181
REST API libraries and API versioning....183
REST API libraries....184
API versioning....185
Authentication and authorization and data validation....187
Authentication and authorization....187
Data validation....189
Error handling and API documentation....191
Error handling....191
API documentation....193
API testing and API gateway....194
API testing....194
API gateway....196
Summary....198
Quiz time....199
Chapter 11: Caching and Asynchronous Messaging in Microservices....200
Client-side caching and edge caching....201
Client-side caching....201
Edge caching....202
Microservice-level caching and database query caching....203
Microservice-level caching....203
Database query caching....204
Message queues and publish-subscribe....205
Message queues....205
Publish-subscribe (Pub/Sub)....207
Event-driven architecture....209
Summary....210
Quiz time....211
Chapter 12: Ensuring Data Security with the Saga Pattern, Encryption, and Security Measures....212
Compensating actions and Saga orchestration....213
Compensating actions....213
Saga orchestration....214
Event-driven communication and Sagas with state....221
Event-driven communication....221
Sagas with state....223
Transport layer security (TLS) and data encryption at rest....224
TLS....224
Data encryption at rest....226
Encryption algorithms and key management....227
Encryption algorithms....227
Key management....229
Authentication, authorization, input validation, secure coding practices, and API rate limiting....231
Authentication....231
Authorization....232
Input validation....233
Secure coding practices....233
API rate limiting....233
Summary....234
Quiz time....235
Part 4: Monitoring and Logging in Microservices with Node.js....236
Chapter 13: Monitoring Microservices in Node.js....238
Structured logging and log levels....239
Contextual information and centralized log management....241
Contextual information in logs....242
Centralized log management....243
Application-level metrics, distributed tracing, and health checks....244
Application-level metrics....244
Distributed tracing....245
Health checks....245
Threshold-based alerts and anomaly detection....246
Threshold-based alerts....246
Anomaly detection....247
Request tracing, request context propagation, and logging frameworks....248
Request tracing....249
Request context propagation....249
Logging frameworks....250
Summary....251
Quiz time....252
Chapter 14: Logging in Microservices with Node.js....254
Choosing a logging framework and defining log levels....255
Choosing a logging library....255
Log levels....258
Structured logging, log transport, and storage....258
Structured logging....258
Log transport and storage....260
Log filtering, sampling, error handling, and exception logging....261
Context propagation, monitoring, and analyzing logs....263
Context propagation....264
Monitoring....264
Log analysis....265
Summary....265
Quiz time....266
Chapter 15: Interpreting Monitoring Data in Microservices....268
Metrics analysis....269
Log analysis....272
Alerting and thresholds....276
Visualization and dashboards....281
Correlation and context....287
Summary....289
Quiz time....291
Chapter 16: Analyzing Log Data in Microservices with Node.js....292
Log levels and severities....293
Request tracing, contextual information, and event sequencing and order....295
Request tracing....295
Contextual information....296
Event sequencing and order....296
Advantages and considerations of request tracing, contextual information, and event sequencing and order....297
Log format, structured logging, and log filtering and search....297
Log format....298
Structured logging....298
Log filtering and search....298
Advantages and considerations of log format, structured logging, and log filtering and search....299
Log aggregation, centralized log management, visualization, and log analysis tools....300
Log aggregation....300
Centralized log management....300
Visualization....301
Log analysis tools....301
Advantages and considerations of log aggregation, centralized log management, visualization, and log analysis tools....301
Correlation of log data with metrics and monitoring data....302
Summary....304
Quiz time....304
Final words....305
Index....306
About Packt....320
Other Books You May Enjoy....321
Do you want to immerse yourself in the world of microservices? Building Microservices with Node.js will guide you through migration from a monolithic architecture to microservices. With this book, you'll acquire a deep understanding of microservices architecture and apply it confidently in your web application projects.
As you progress, you'll be guided through the process of creating a simple application and incorporating the Node.js framework into it, along with its commonly used libraries. You'll learn how the framework operates, how to configure it, and how to develop handlers for the web framework. Furthermore, you'll explore how to deploy your application to a production server while going through the intricacies of JavaScript and Node.js. Later chapters will show you how to approach microservices in Node.js, implement them effectively, and integrate RESTful APIs. Additionally, you'll gain insights into service-to-service authentication and authorization and learn how to work with databases and caching. To ensure a comprehensive understanding of the topic, you'll get to grips with monitoring and logging in microservices with Node.js.
By the end of this microservices book, you'll be able to develop a web app using the Node.js framework, configure it, extend it using libraries available for this framework, and launch it using best practices.
This microservices and Node.js book is for backend developers, full-stack developers, software architects, and frontend developers who want to venture into the world of backend development and extend their capabilities. A fundamental understanding of the JavaScript ecosystem will be helpful but not necessary, as this book will cover the essentials of backend development, JavaScript programming, and Node.js.