Hands-On Microservices with JavaScript
Contributors
About the author
About the reviewer(s)
Preface
Who this book is for
What this book covers
To get the most out of this book
Download the example code files
Conventions used
Get in touch
Share Your Thoughts
Download a free PDF copy of this book
Part 1:Fundamentals of Microservices Architecture
Chapter 1: Introduction to Microservices
Introducing microservices
Moving toward microservices
Understanding a big ball of mud
Understanding the software development process
Exploring the monolith approach
What is service-oriented architecture?
The differences between SOA and microservices
Advantages of microservices
Disadvantages of microservices
Summary
Chapter 2: Diving into Microservices Internals
Solidifying the communication
Microservice communication techniques
Introduction to APIs
What exactly is REST?
HTTP-based REST implementation
HTTP response status codes
Introduction to GraphQL
Remote Procedure Call
Synchronous microservice communication
Asynchronous microservice communication
Essential communication patterns
Message brokers
Summary
Chapter 3: What Do You Need Before Getting Started?
Technical requirements
JavaScript essentials
JavaScript engine
JavaScript runtime
Callback-based asynchronous JavaScript
The way to promises
Promise API
Async/await in JavaScript
Microtask queue
Node.js essentials
Summary
Chapter 4: Stack Development Technologies
Technical requirements
Node.js and its installation
Installing Node.js for Windows
Installing Node.js for macOS and Linux
Node.js frameworks
Express.js
NestJS
Choosing between Express.js and Node.js
Choosing the right IDE
Understanding and installing Docker
Understanding and installing Apache Kafka
Understanding and installing Git
Installing Postman
Installing MongoDB
Summary
Part 2:Building and Managing Microservices
Chapter 5: Basic CRUD Microservices
Technical requirements
Understanding business requirements
Tools to develop a basic microservice
Preparing our first project
Understanding the concept of packages
Understanding the package.json file
Understanding index.js files
Installing the required packages
Defining the internal architecture of our microservice
MVC architectural pattern
Integrating MVC into our Node.js project
Hands-on account microservice development
Implementing our data-access functionalities
Implementing the M in MVC
Storing configuration
Implementing the business layer
Implementing the controller
Simple data validation for your API
Implementing routing
Constructing our web application
Combining all the elements
Running and testing our first microservice
Creating a new account
Getting an account by ID
Updating an account by ID
Gettings all accounts
Deleting account by ID
Summary
Chapter 6: Synchronous Microservices
Technical requirements
Understanding the requirements for the transaction microservice
Tools to develop the transaction microservice
NestJS
Docker
Prisma ORM
Hands-on transaction microservice development
Dockerizing your PostgreSQL instance
Modeling the data
Seeding test data
Implementing the transaction service
Configuring Swagger
Working on transaction implementation
Establishing synchronous communication with the account microservice
Summary
Chapter 7: Asynchronous Microservices
Technical requirements
Understanding the requirements
Exploring asynchronous communication
Implementing an asynchronous transaction microservice
Getting started with Kafka for NestJS
Cluster and brokers in Kafka
Topic and partition concepts in Apache Kafka
Configuring Apache Kafka
Adding an asynchronous nature to a transaction microservice
Adapting an account service to new requirements
Testing our microservices together
Summary
Chapter 8: Real-Time Data Streaming Using Microservices
Technical requirements
What is real-time streaming?
Why real-time data is essential
Understanding use cases
Relationship between real-time streaming and microservices
Microservices we will develop
Getting started with an earthquake streaming API
Implementing the earthquake stream consumer
Summary
Part 3:Securing, Testing, and Deploying Microservices
Chapter 9: Securing Microservices
Technical requirements
Security, authentication, and authorization in microservices
Understanding security
Exploring authentication
Defining authorization
Best practices for authorization
Difference between authentication and authorization
Getting started with JWTs
Implementing an Authentication microservice
Integrating token-based authentication for the account microservice
Summary
Chapter 10: Monitoring Microservices
Technical requirements
Importance of observability
Introduction to logging
Logging levels and node libraries
Log formats
Best practices for logging
Implementing logging in your microservices
Centralized logging with Elasticsearch, Logstash, and Kibana (ELK) stack
A brief introduction to Logstash
A brief introduction to Elasticsearch
A brief introduction to Kibana
Summary
Chapter 11: Microservices Architecture
Technical requirements
Getting started with an API gateway
How an API Gateway works
Single versus multiple API gateways
Implementing microservices using an API gateway
CQRS and event sourcing
Understanding CQRS
Event sourcing
Event store
Implementing CQRS and event sourcing
Commands and handlers
Implementing an aggregate root
Implementing projection
Implementing API functionalities
Testing an application
Service Registry and discovery in microservices
Understanding Service Registry and discovery
Approaches for implementing Service Registry and Discovery
Implementing Service Registry
Summary
Chapter 12: Testing Microservices
Technical requirements
Understanding testing in a microservice architecture
Understanding unit tests
Introducing unit testing packages
What should we test in unit testing?
Implementing unit tests for the account microservice
Writing unit tests for the transaction microservice
Comparing mocks, stubs, and spies in unit tests
Mocks
Stubs
Spies
Understanding and implementing integration tests
Summary
Chapter 13: A CI/CD Pipeline for Your Microservices
The essentials of CI/CD processes
Understanding CI
Understanding CD
Integrating CI/CD into microservices
Working with Azure Cloud
Working with GitHub Actions
Understanding Secrets
Building a pipeline
Summary
Index
Why subscribe?
Other Books You May Enjoy
Packt is searching for authors like you
Share Your Thoughts
Download a free PDF copy of this book
Keep up with the ever-evolving web development landscape by mastering JavaScript microservices with expert guidance from Tural Suleymani—a full-stack software engineer, architect, software development teacher, Microsoft MVP, and three-time C# Corner MVP. He distills over a decade of experience crafting high-performance, scalable solutions into this guide. He’ll walk you through the fundamentals of microservices, providing a solid foundation in architecture, design principles, and the necessary tools and technologies. From beginners to seasoned developers, this book offers a clear pathway to mastering microservices with JavaScript.
With the help of hands-on tasks that simulate real-world scenarios, you’ll learn how to build reliable and scalable microservices. You’ll explore synchronous and asynchronous communication, real-time data streaming, and how to secure and monitor your services. The book’s emphasis on a design-first approach ensures that your microservices are maintainable and future-proof. Detailed case studies from industry experts will enhance your learning experience and provide practical insights into building microservices in production environments.
By the end of this book, you'll be ready to create cloud-ready, high-performing microservices using cutting-edge JavaScript frameworks and tools and tackle real-world challenges, ensuring your applications are secure and efficient.
Understand synchronous and asynchronous communication between microservices
Discover how to decouple microservices using Message Broker
Build real-time data streaming microservices with JS frameworks
Understand logging and monitoring in microservices
Explore common architectural patterns for microservices
Cover microservices with unit, and integration tests
Apply CI/CD for microservices and learn to Dockerize and deploy them
This book is for backend developers, full-stack developers, software architects, and frontend developers who want to venture into the world of microservices. A fundamental understanding of the JavaScript ecosystem will be helpful but not necessary, as this book will cover the essentials of microservices architecture, JavaScript programming, and modern frameworks and tools for building scalable, maintainable applications.