Get started Bring yourself up to speed with our introductory content.

'Practical Microservices' speaks the language of web developers

In his book, 'Practical Microservices,' Ethan Garofolo introduces web developers to the coding principles that form the foundation for microservices-based applications.

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.

Although the concepts behind microservices are not too complex -- and, theoretically, only require a proficiency in JavaScript and web development -- there is still a dissuading air of mystery that seems to surround the topic.

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?

This book targets developers who have experience building web-based applications in a language, such as JavaScript, but are just getting started with microservices.

"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."

Garofolo believes readers don't necessarily need experience shipping a commercial web application before familiarizing themselves with microservices. Garofolo wrote this book purely with web developers in mind, a feeling reflected in the use of JavaScript for the coding tutorials.

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."

Garofolo chose to use JavaScript and PostgreSQL for this tutorial because of their familiarity to most web developers, as opposed to any particular love of JavaScript. Garofolo identified Ruby as his personal preference for microservices development,  specifically since the language allows him to use Eventide, a comprehensive microservices development toolkit. However, he stressed that he didn't want the specifics of any one language to obscure the principles in the book.

"There's nothing really in the book that is specific to JavaScript," Garofolo said. "But, if I had chosen Ruby, I think it would have made it far less accessible. I wanted the ideas to really matter, [which] transcend programming language."

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.

Dig Deeper on Service orchestration

SearchSoftwareQuality
SearchCloudComputing
TheServerSide.com
Close