The API Approach to Microservices and Lessons Learned From SOA
If IT today has a watchword, it's “speed.” At the same time, IT is expected to protect the organization’s crown jewels and to keep services available and responsive.
Join the DZone community and get the full member experience.Join For Free
if it today has a watchword, that word is “speed.” at the same time, it is expected to protect the organization’s crown jewels (company finances and private customer records) and to keep services available and responsive. the message: go faster, but don’t break anything important. even facebook has modified its motto on this front from “move fast and break things” to “move fast with stable infrastructure.”
in response to these pressures, enterprise it teams are increasingly adopting the techniques in use at cutting-edge web-scale companies like amazon, google, netflix, and facebook , characterized as microservices . simplistically, microservices attempt to take slow-changing, monolithic functionality and break it apart into many small pieces that can be changed independently of one another. the traditional change management role has moved away from “command and control” and into a highly automated deployment model that often resembles barely controlled anarchy. while this approach can look chaotic, it is reinforced by strong rigor around the safety of change and responsiveness to the user.
taken at face value, the microservices approach seems like a logical method to evolve a traditional enterprise architecture to satisfy the market pressures of speed.
deconstructing monolithic architecture into smaller, independent pieces seems to many organizations like a natural evolution of soa . in many regards, this is true, but it can lead to putting the focus on the wrong areas.
soa lessons learned
one of the major challenges enterprises faced when attempting to gain value from the soa approach was a tendency to overthink the design of services and to become paralyzed by debates about service granularity and adherence to pure architectural principles. while the design aspect of soa was important, it caused many organizations to fail to deliver on the promises of more efficient it delivery while they centered on the early design stages and had to rush through the operational aspects. today, as teams adopt microservices, operational considerations are once again overlooked.
a significant amount of the informational material available around microservices focuses on issues like what a microservice is, how to design one (often using techniques like domain-driven design), and whether or not something is a microservice. in my experience, the design of a microservice is the least interesting part of the approach. the behaviors are far more important. after all, it is not the design of a microservice that makes it interesting. it's the fact that it allows teams using the approach of delivering new features on an hourly or daily basis, rather than the relatively glacial paces that characterize traditional techniques. does it matter if a microservice is perfectly designed if you can only push it into production once a week?
realizing this means we can look at microservices from a different, more practical perspective. we should consider what aspects of the approach are contingent in enabling safe, predictable, hourly updates. automated testing and deployment are obvious and essentially mandatory. it may be plausible to manually test and deploy microservices when you only have one or five of them. but the nature of the approach means that with success comes hundreds or thousands of microservices, and introducing human error in the deployment process is simply infeasible.
similarly, when dealing with such a large number of interrelated components, all of which depend on shared supporting services like interprocess communications, security, and monitoring, a happy path approach to testing the system doesn’t cut it. with any system this complex, all we know for sure is that things will break, they’ll break often, and they’ll often break in unpredictable ways. this observation leads successful microservice teams not only to focus on building microservices in defensive ways but also to introduce frequent deliberate breakages in environments in order to confirm that the systems and teams are capable of resolving any problems rapidly and effectively. netflix’s famous simian army is a concrete example of such an approach.
designing for failure is fundamental to the success of large-scale microservice deployments like netflix or google. however, those organizations typically don’t need to address another key challenge that enterprises adopting microservices must face: providing a stable, safe interface between the high-scale, highly complex, and rapidly evolving microservices environment and the existing enterprise assets that underpin the business. for an established enterprise, there must be a secure and manageable solution to connect microservices with the massive business value embedded within its monoliths.
the complexity of a large-scale microservices architecture cannot be overstated. in many cases, these organizations cannot even draw a high-level architecture diagram of their deployment. instead, they have to resort to automatically generated dependency diagrams, colloquially referred to as death star diagrams because of their amusing resemblance to the titular planetary destroyer. how can enterprise developers navigate this complexity, and at the same time bridge the gaps between these modern services and traditional systems? the answer, of course, is apis .
apis to the rescue
at mulesoft, we understand the value of using apis to provide a manageable interface between it assets that work at different speeds — what gartner has referred to as bimodal it . well-managed apis provide a robust option to manage the different speeds of change happening on both sides.
in a microservices approach, managed apis are not only necessary, they are assumed. when you look closely at the death star diagrams, you can see that the fundamental interconnect point is the api . it becomes possible to visualize these complex networks of logical dependency and impact only because each microservice exposes a well-known, versioned, and managed api endpoint. when apis are managed effectively, they help ensure safe changes, regardless of the speed of deployment exhibited by the components on either side of the api contract.
apis can also be used to define and manage your microservices. at mulesoft, for example, we use a framework called khartos to simplify the development of our node.js-based microservices. khartos essentially forms an opinionated microservice container that exposes the microservice contract as an api specified in raml , the open, easy, and reuse-centric api specification language, and employs dependency injection to automatically configure key aspects of the microservice to naturally “plug in” to our platform services. this means the developer can define the microservice api first without any overhead, speeding up the development cycle while also getting a lot of capabilities “for free.”
mulesoft’s anypoint platform for apis puts this same power into the hands of enterprise teams, allowing developers who are working on traditional monolithic stacks or microservice architectures to design, manage, and collaborate around apis regardless of the speed of change. essentially developers are able to build application networks using apis to connect applications, data, and devices, making them pluggable and reusable.
one of the benefits gained from managing microservices via apis is achieving lightweight, developer-friendly governance, in particular around:
- service discovery and documentation. api portals provide self-service documentation, consoles, sdk client generation, and programmable notebooks to allow developers to discover and learn how to consume the api for a microservice.
- fault tolerance. api gateways proxy restful communication between microservices, providing a central point to ensure that policies, like security and throttling, are correctly applied across all microservices.
- quality of service. cascading failure is a risk with microservices architecture. mule runtimes deployed as api gateways can act as “circuit breakers” to quickly detect and isolate services from cascading failure.
- security. security should be part of the development process, not a feature that developers have to remember to repeat. api gateways provide out-of-the-box policies for security, including oauth 2.0, to ensure that the correct security policies are applied to a set of apis without the developer having to think too hard about it.
managing microservices via apis has two important benefits: on one hand, you provide tooling to make it easy to adopt good practices (such as khartos), while, on the other hand, you use api management to ensure policies are applied consistently and correctly without having to manage many versions of client libraries in the microservices themselves. this further reinforces the approach of “move fast, but with stable infrastructure.”
governance can be further enabled through automation and continuous delivery, which ensures the application of correct standards in a rapid and seamless manner.
continuous delivery of composed applications
getting teams into a habit of continuously releasing software aligns with agile development principles. in terms of microservices applications, continuous delivery also means continuous integration. in applications that are composed of many services, it is critical to ensure that the composition actually works when the software is built. mulesoft’s anypoint platform fully integrates into a continuous delivery strategy, both for the implementation and management of api- driven microservices:
- api- defined and event-driven microservices built with anypoint platform can be declaratively tested with the munit framework, mulesoft’s automated integration and unit testing framework.
- mule applications are agnostic to version control systems and use maven as their underlying build system. as a result, mule application builds can integrate with virtually any automated build system, including jenkins and bamboo. testing and application analytics services like testflight and crashlytics are similarly easy to integrate into the mule sdlc (software development lifecycle).
operational automation is crucial in achieving continuous delivery. mulesoft’s sdlc framework integrates building, packaging, deploying, and managing mule microservices into a variety of deployment ecosystems.
deploying container technology
iaas frameworks, such as chef and puppet, and virtualization technology, such as vmware and xen, can greatly accelerate the deployment of monolithic application stacks. recent advances in container technology, particularly frameworks such as docker and rocket, provide the foundation for consistent, repeatable deployment of applications without necessarily provisioning new physical or virtual hardware. numerous benefits arise from this deployment paradigm, including increased compute density within a single operating system, trivially simple autoscaling, and container packaging and distribution.
these advantages make containers the ideal choice for microservice distribution and deployment. container technologies follow the microservice philosophy of encapsulating a single piece of functionality and doing it well. they also give microservices the ability to scale elastically in response to increasing demand.
however, there is never a free lunch. managing a container ecosystem comes with its own challenges. for instance, containers running on the same host must be bound to ephemeral ports to avoid conflicts; container failure must be addressed separately; and containers need to integrate with front-end networking infrastructure such as load balancers, firewalls, and perhaps software-defined networking stacks. platform-as-a-service technologies, such as pivotal cloud foundry and mesosphere dcos, are emerging to address these needs.
anypoint platform ’s runtime components support a variety of deployment mechanisms, ranging from traditional, multitenant, cluster-based deployment to a mule worker packaged and deployed as a container in a paas framework. mule runtimes deployed as api gateways can be similarly packaged and deployed as proxies for a single microservice or, more commonly, deployed as an infrastructure component of a paas to govern all microservice api interaction. the anypoint platform runtime (aka mule) has the following attributes that make it a perfect fit for containerization:
- the runtime is distributed as a standalone zip file, with a jvm being the only dependency.
- it runs as a single, low-resource process. for instance, it can easily be embedded in a resource-constrained device like a raspberry pi.
- it has no database or data storage requirements. logging can be configured to standard output and standard error.
the mule runtime can execute a microservice application artifact. the application artifact is a self-contained zip file that contains all the required libraries and configuration. this makes it easy to bundle or layer runtime installation and application artifacts as a single container image.
when running in a microservices model, the mule runtime and application are combined in a container. the mule application container image can be layered atop the mule runtime container image. each service is a thin layer atop the runtime container, overriding mule_install_dir/apps. in this model, the mule microservice lifecycle (start/stop) is bound natively to the container’s lifecycle, making it easy to work with container orchestration management systems.
the anypoint runtime manager provides a single operational plane to manage both the microservice implementations built with the anypoint platform and the api gateways. the anypoint runtime manager can either be hosted by mulesoft or deployed as part of the management layer of a paas infrastructure, providing an operational api to orchestrate microservice deployments, api monitoring, analytics-based promotion, and other concerns.
there is no question that microservices are here to stay. the benefits of rapid, safe microservices deployments are too great to ignore. however, no approach is the right fit for all use cases. one of the major challenges will be learning to mix and match microservices with the many other architectural styles in the enterprise.
enterprises must also learn to manage the speed and flexibility that microservices enable and the complexity that microservices create. microservices encourage much more frequent iterations than traditional applications, with production changes in the tens to hundreds a day being common. the large numbers of microservices that make up successful deployments require an effective, automated means to manage them. finally, few enterprises can completely replace their existing assets and investments with all-new, microservice-based architectures, so a coexistence strategy is required.a
managed apis provide an effective, standardized option to manage microservices at scale, while also supporting and leveraging the rest of the enterprise’s assets. the value of apis as the practical means to manage microservice complexity in the composable enterprise has never been clearer.
to read more about microservices, check out our best practices for microservices whitepaper for design principles and how anypoint platform can help you implement microservices best practices in your organization.
Published at DZone with permission of Conor Curlett, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.