By this point, plenty of web developers have at least heard of microservices. Unfortunately, fewer are familiar with the fundamental principles that define this architectural design style -- let alone know the mechanics of coding a microservices-based application.
This is the problem that Ethan Garofolo, a software architect at Berkadia Commercial Mortgage, sought to address in his book Practical Microservices. The goal, he said, is to provide developers a straightforward, digestible introduction to the mechanics of microservices-based programming. And, while Garofolo stressed that he does not intend this book to be anything but a hands-on coding tutorial, he hopes to help developers understand some of the core philosophies that transcend specific language and technology choices.
Who is this book for?
"In the Pragmatic Bookshelf bookstore, it's listed as 'intermediate,' in the sense of a developer's skills," Garofolo said. "But as far as microservices, specifically, it's definitely a beginner's book."
Want to sample the book for yourself? Click here to read the second chapter of Ethan Garofolo's Practical Microservices and learn about the basics of messaging in microservices.
Understanding objects vs. events
Microservices development is often associated with an embrace of object-oriented programming principles such as SOLID. Although these are fundamental concepts, Garofolo said, taking the next step into true microservices development requires an understanding of events and their role in distributed service communication -- especially for developers who have been entrenched in model-view-controller (MVC) design and CRUD cycles.
To that point, Garofolo believes developers need to dispense with thinking of application components strictly as message-based objects. Instead, they should understand how to identify application components and services through the lens of dynamic, action-inducing events. Breaking the mental attachment to webs of direct calls between HTTP servers will demystify the core practices that nourish a microservices-based architecture.
Since a microservices architecture consists of thousands of message-based transactions, following the traditional MVC route that forces tightly coupled services to send requests linearly through the server and database will inevitably present paralyzing application performance and management issues. Instead, these services require asynchronous communication processes that enable them to interact and share information directly without rigid database retrieval processes.
This should not be too hard for developers to achieve, since transactional data is routinely stored within the rows of a supporting database. Rather than throw away the details of various communication processes, developers can save these messages as timestamped events that encapsulate the application's state.
"We've got all these events defined, and the pieces of our system [communicate] via a pattern called pub/sub," Garofolo explained, referencing the publish-subscriber model that enables asynchronous service communication via an abstracted message broker or event bus. "I've already got these events modeled and defined -- why don't I just save them instead of discarding them?"
If developers can train services to understand and retrieve state information by passing information about these events -- a technique Garofolo identified as event-sourcing -- the database and server will no longer inhibit streamlined service communication. This allows teams to retrieve state information quickly, and then reconfigure an application's current state on-demand as needed, which alleviates the management problems microservices pose.
The project and the language
The book's running project takes developers through the process of creating a "YouTube clone" application. From the ground up, developers build an app that simulates the process of registering, submitting and cataloging videos, as well as creating a system to reliably track the number of user views. Using a combination of Node.js and a PostgreSQL relational database, Garofolo walks readers through every step of coding and connecting this collection of services and functions.
"[This] demonstrates how to create a common service for universal consumption, while maintaining clear boundaries between the services and the teams that manage them," Garofolo said. "You'll learn how services interact with one another, not just the flow of that HTTP layer down to the service."
Editor's note: Ethan Garofolo would like to acknowledge and thank Scott Bellware, co-founder of Eventide, for introducing him to event-sourcing concepts, particularly the publisher-subscriber model detailed in this article.