Practical Microservices

Book description

MVC and CRUD make software easier to write, but harder to change. Microservice-based architectures can help even the smallest of projects remain agile in the long term, but most tutorials meander in theory or completely miss the point of what it means to be microservice-based. Roll up your sleeves with real projects and learn the most important concepts of evented architectures. You'll have your own deployable, testable project and a direction for where to go next.

Much ink has been spilled on the topic of microservices, but all of this writing fails to accurately identity what makes a system a monolith, define what microservices are, or give complete, practical examples, so you're probably left thinking they have nothing to offer you. You don't have to be at Google or Facebook scale to benefit from a microservice-based architecture. Microservices will keep even small and medium teams productive by keeping the pieces of your system focused and decoupled.

Discover the basics of message-based architectures, render the same state in different shapes to fit the task at hand, and learn what it is that makes something a monolith (it has nothing to do with how many machines you deploy to). Conserve resources by performing background jobs with microservices. Deploy specialized microservices for registration, authentication, payment processing, e-mail, and more. Tune your services by defining appropriate service boundaries. Deploy your services effectively for continuous integration. Master debugging techniques that work across different services. You'll finish with a deployable system and skills you can apply to your current project.

Add the responsiveness and flexibility of microservices to your project, no matter what the size or complexity.

What You Need:

While the principles of this book transcend programming language, the code examples are in Node.js because JavaScript, for better or worse, is widely read. You'll use PostgreSQL for data storage, so familiarity with it is a plus. The books does provide Docker images to make working with PostgreSQL a bit easier, but extensive Docker knowledge is not required.

Publisher resources

View/Submit Errata

Table of contents

  1.  Acknowledgments
  2.  Introduction
    1. Telling a Tale of a Different Kind of Keyboard
    2. What This Book Is
    3. What This Book Isn’t
    4. Separating Principles from Implementations
    5. Using This Book
    6. Using Node.js
    7. Strapping In
  3. Part I. Fundamentals
    1. 1. You Have a New Project
      1. Kicking Off Video Tutorials
      2. Building the Bones
      3. Mounting Middleware
      4. Injecting Dependencies
      5. Taking the Server for a Spin and Starting the Database
      6. Serving the Home Page
      7. Connecting the Home Page Application
      8. Mounting the Home Application into Express
      9. Building the Record Views Application
      10. Recording State Changes
      11. Charting a New Course
      12. What You’ve Done So Far
    2. 2. Writing Messages
      1. Unmasking the Monolith
      2. Trying to Compress Water
      3. Extracting “Microservices”
      4. Defining Services
      5. Getting Components to Do Things
      6. Representing Messages in Code
      7. Naming Messages
      8. Storing State as Events
      9. Storing Messages in Streams
      10. Defining Component Boundaries
      11. Recording Video Views
      12. Writing Your First Message
      13. (Re)configuring the Record-Viewings Application
      14. Hanging a Lantern
      15. What You’ve Done So Far
    3. 3. Putting Data in a Message Store
      1. Defining Requirements
      2. Fleshing Out Message Structure
      3. Surveying Message DB
      4. Scaffolding the Message Store Code
      5. Connecting to Message DB
      6. Writing write
      7. Adding Optimistic Concurrency Control to Our Writes
      8. “Can’t Kafka Do All of This?”
      9. What You’ve Done So Far
    4. 4. Projecting Data into Useful Shapes
      1. Handling Events
      2. (Re)Introducing the RDBMS
      3. Writing Your First Aggregator
      4. Handling Asynchronous Messages
      5. Getting Idempotent with It
      6. Connecting to the Live Message Flow
      7. Configuring the Aggregator
      8. Having the Home Page Application Use the New View Data
      9. Coming to Terms with Data Duplication
      10. What You’ve Done So Far
    5. 5. Subscribing to the Message Store
      1. Sketching the Subscription Process
      2. Managing the Current Read Position
      3. Fetching and Processing Batches of Messages
      4. Orchestrating the Subscription
      5. Reading the Last Message in a Stream
      6. Reading a Stream’s Messages
      7. Adding the Read Functions to the Message Store’s Interface
      8. Starting the Server
      9. What You’ve Done So Far
  4. Part II. Fleshing Out the System
    1. 6. Registering Users
      1. Discovering Domain Messages
      2. Starting with the Business Process
      3. Translating the Business Processes into Events and Commands
      4. Fleshing Out the Identity Messages
      5. Examples from Other Domains
      6. Adding Registration to Our System
      7. Turning Registration Requests into Commands
      8. Superficially Validating User Input
      9. Ensuring Uniqueness of Email Addresses
      10. Finishing the Application
      11. Validating Eventually Consistent Data
      12. Coping with Trade-Offs
      13. What You’ve Done So Far
    2. 7. Implementing Your First Component
      1. Fetching a Stream’s Current State
      2. Joining the “I Wrote a Microservice” Club
      3. Wiring the Identity Component into the System
      4. Disambiguating “Projections” and “Replaying”
      5. Taking It Further
      6. What You’ve Done So Far
    3. 8. Authenticating Users
      1. Aggregating Registered Events
      2. Discovering the Authentication Events and Commands
      3. Letting Users in the Door
      4. Using Third-Party Authentication
      5. What You’ve Done So Far
    4. 9. Adding an Email Component
      1. Discovering the Email Component Messages
      2. Addressing Idempotence
      3. Adding the Component
      4. Sending the Email
      5. Running the Component
      6. Adding Email to the Registration Process
      7. Recording Registration Emails
      8. Making the Message Store Aware of Origin Streams
      9. Revisiting Idempotence
      10. Orchestrating Components vs. Choreographing Components
      11. What You’ve Done So Far
    5. 10. Performing Background Jobs with Microservices
      1. Accidental Complexity
      2. Use Case #1: Sending Emails
      3. Use Case #2: Transcoding Videos
      4. Describing the Creators Portal
      5. Aggregating Is Also for Other Teams
      6. Building the Video Publishing Component
      7. Accepting Potential Duplication
      8. What You’ve Done So Far
    6. 11. Building Async-Aware User Interfaces
      1. Defining Video Metadata Messages
      2. Responding to Users When the Response Isn’t Immediately Available
      3. Adding Validation to a Component
      4. Aggregating Naming Results
      5. Applying Naming Events to the Creators Portal View Data
      6. Justifying Our UI Decision
      7. What You’ve Done So Far
  5. Part III. Tools of the Trade
    1. 12. Deploying Components
      1. Creating the Heroku “App”
      2. Configuring the “App”
      3. Installing Message DB
      4. Deploying the System
      5. Distributing the System
      6. Deploying Databases
      7. What You’ve Done So Far
    2. 13. Debugging Components
      1. Priming the Database with Example Data
      2. Introducing the Admin Portal
      3. Creating Users
      4. Wiring the Users View into the Admin Portal
      5. Hooking the Admin Portal into the Rest of the System
      6. Inspecting the Results So Far
      7. Thinking Through the Expected Flow
      8. Correlators Gonna…Correlate?
      9. Imagining Our Way to Good System Monitoring
      10. Starting from the Beginning
      11. Viewing Messages by Stream
      12. Augmenting the Message Store for $any and $all
      13. What You’ve Done So Far
    3. 14. Testing in a Microservices Architecture
      1. Revisiting the Fundamentals
      2. Writing Tests for Autonomous Components
      3. Writing Tests for Message-Writing Applications
      4. Keeping It Simple
      5. Dropping Testing?
      6. What You’ve Done So Far
    4. 15. Continuing the Journey
      1. Handling Concurrency
      2. Snapshotting
      3. Changing the Message Contract
      4. Using Different Programming Languages
      5. Making Use of Monoliths
      6. What You’ve Done So Far
  6. A1. ES6 Syntax
    1. const and let
    2. Arrow Functions
    3. Object Destructuring
    4. Object Literal Property Value Shorthand

Product information

  • Title: Practical Microservices
  • Author(s): Ethan Garofolo
  • Release date: April 2020
  • Publisher(s): Pragmatic Bookshelf
  • ISBN: 9781680506457