I often see engineers and even executives get hung up on the “Microservices vs. Web services” terminology as if it were an either-or choice. It simply is not.
Since web services and microservices are not a replacement for each other, the best way to learn about the differences between the two is by understanding each one of them, their types, their benefits, and their challenges.
What is a Web Service?
In a nutshell, a webservice is a unit of functionality exposed as a “service” over the “web”.
Simple enough, right? 🙂
In the case of web services, “over the web” typically means “HTTP” (secure HTTP, or HTTPS, to be precise).
A “Web Service” is how we expose data and functionality to other systems in a platform-agnostic way. “Other systems” is the key here. The intended audience for web services is always another “system, ” which could be another web service or a user interface application.
What is a Microservice?
Microservice is a relatively modern architectural style that structures an application or business capability as a collection of small (micro), independently deployable functional services.
Structuring an application as a collection of microservices allows for increased development velocity, operational agility, and scalability.
You can set up autonomous teams, each working on a set of microservices and making changes to them independently without affecting other parts of the larger solution.
Microservices architecture is an alternative to the monolithic application architectural style.
Web services can be packaged and deployed as a microservice OR they can be part of a monolith.
A microservice can be a web service, but it doesn’t have to. For example, it can be a micro user interface or an event-driven microservice.
Webservice vs. Microservice: Their Types
Types of Web Services
There are different types of web services based on the request-response model they support.
The two most popular ones are REST and SOAP.
REST and SOAP Web services can both be implemented as part of a larger monolith or as independent microservices.
Modern microservices architectures typically implement web services as REST web services due to the advantages of REST vs. SOAP.
Types of Microservices
You can classify microservices in a couple of different ways.
First, you can say there are different types of microservices based on the programming model they use.
The two most popular programming models for mircoservices are event-driven and request-driven.
Event-driven microservices are triggered by events and typically use an event streaming layer such as Kafka or messaging layer such as MQ.
Request-driven microservices are nothing but web-services that are invoked by making an HTTP request to them.
Another way to classify microservices is based on the nature of the capability they provide. You can have either UI microservices (often called micro front ends) OR middleware microservices (often when people say “microservices”, they are typically referring to middleware microservices)
Webservice vs Microservice: Difference in their Benefits
Benefits of Web Services
The main benefit of web services is that web services enable interoperability driven by standards between systems.
Before the rise of web services, the only way to expose data and functionality from one system to another was through a custom integration solution. This meant building a solution from scratch whenever you wanted to connect two systems.
Web services drove a huge change by providing a standard way – XML over HTTP (SOAP) or JSON over HTTP (REST) – to expose data and functionality as services.
This lowered the cost and time of integration, allowing enterprises to adopt paradigms such as service oriented architecture (SOA) and allowing an ecosystem of developer and test tools to flourish.
Benefits of Microservices
Much has already been said about the benefits of microservices. However, the main advantage of microservices is that it allows enterprises to be more agile and innovative and improve their time to market.
Microservices vs. Web services: Difference in Getting Started
Planning for web services should first center around the web service interface.
What data or functionality should it expose to its callers and in what format (REST or SOAP. What does the contract look like).
Once the interface is agreed upon, developers can leverage appropriate standards and frameworks (e.g. Spring Boot or just plain JAX-WS / JAX-WS) to implement the web services. Deployment and monitoring strategies for a given web service will vary depending on whether the web service is deployed as microservice(s) or part of the monolith.
Microservices, on the other hand, is an enterprise architectural style, and as such is a complex undertaking requiring up front planning, architecture and buy-in from key stakeholders and sponsors. When it comes to implementing microservices, developers typically rely on a microservice framework.
Conclusion
So, what is the difference between web services and microservices? Here are the most important differences between the two –
1. Web services are a way to expose data and functionality as services. Microservices are an architectural style to improve feature velocity and business agility.
2. Web services can be (but don’t have to be) packaged & deployed as microservices and microservices can implement web services (but don’t have to)
3. Web services focus more on the standard (SOAP vs. REST) and format of the request-response exchange between the web service and its caller. Microservices focus more on effectively developing, deploying, and operating micro applications at scale as part of a larger solution or business capability.
Top Questions related to Webervices vs Microservices
1. What is the difference between webservices and microservices?
Web services are a way to expose the data and functionality, while microservices is an architectural style to improve feature velocity and business agility. Web services can be packaged and deployed as microservices, and microservices can implement web services.
2. What is the focus of a web service?
The Focus of a web service is the format of the request-response exchange between the web service and its caller as well as functional error handling.
3. What is the focus of a microservice?
The focus of microservice is increasing team autonomy and agility through effective development, deployment, and management of micro applications at scale. These micro applications, called microservices are typically part of a larger solution or business capability.
4. Is microservice a web service?
It could be but not necessarily. A microservice could be a web service or an event driven microservice. Not all microservices are web services.
5. Is Web service a microservice?
It could be but not necessarily. A web service could be packed and deployed as a microservice but it is also common for large monoliths to expose web services, sometimes hundreds of web services. In short, not all web services are packaged and deployed as microservices.
6. Are all web services microservices?
No. Not all web services are microservices. Web services could be microservices or could be part of a large monolith.
7. Are all microservices web services?
No. Not all microservices are web services. Microservices could be web services exposing a REST or SOAP service over HTTP OR they could be event driven services that perform work on an event trigger.
8. What is the difference between microservices vs Rest API?
Rest or “representational state transfer” is a way to format the request and response in a web service. Rest APIs are APIs that conform to that Rest style of request-response exchange format. Rest APIs are web services that can be structured and deployed as microservices or they could be part of a bigger monolithic application.
9. What is the difference between microservices and containers?
Containers are a type of virtualization technology. According to Docker, “A container image is a lightweight, standalone, executable package of software that includes everything needed to run an application: code, runtime, system tools, system libraries and settings“. Microservice, on the other hand, is a way to structure code and capability as small loosely coupled but cohesive micro-applications. Microservices can be packaged and run as containers but they are not the same thing.
10. What is the difference between packaged business capabilities and microservices?
Packaged business capabilities are one or more technology artifacts packaged and deployed as self-contained, independent units to allow for independent development, deployment, and management of that business capability. Microservices are similar in that they are small loosely coupled applications, but the focus is more on feature velocity and business agility rather than packaging and deploying discrete business capabilities.
Microservices can be used to package discrete business capabilities, but the primary goal is to achieve feature velocity and team autonomy by having each microservice own a small part of a larger business capability.
Packaged business capabilities could include web services, mobile applications, ETL processes, and more.
Microservices are typically packaged as container images and deployed to a container platform such as Kubernetes.
Microservices focuses on the architectural and deployment patterns, whereas PBCs focus more on the business capability surfaced by a certain unit of packaged artifacts and applications.
11. Where should you not use microservices?
Microservices do not always fit every scenario and may be overkill in some situations. Some scenarios where microservices may not be suitable include:
- When all the services needed to fulfill one business capability can be bundled in a single monolith application
- When developing a very simple project with few services
- You have a single, small team managing the entire business capability
- You don’t have the skills or resources to manage the operational complexities that come with microservices.
12. What is the opposite of microservices architecture?
Monolithic architectures cane be viewed as extreme opposite of microservices architectures. Monolithic architectures typically bundle all the services, and stored procedures necessary to execute a business capability in one single application. Monolith application is typically worked on by multiple teams at the same time. This type of architecture can result in slow development velocity, lack scalability and resiliency.
Modernization patterns such as strangler fig provide a pathway to modernize a monolith into microservices.