DEV Community

Cover image for A Curious Encounter: Unraveling the Roles of Microservices, API Gateways, and API Servers

A Curious Encounter: Unraveling the Roles of Microservices, API Gateways, and API Servers

Srishti Prasad on December 28, 2024

It all started during one of my routine code reviews at work. I was reviewing a piece of functionality that had recently been implemented. The task...
Collapse
 
phototrip_8f65aa1941692af profile image
PhotoTrip • Edited

I think you need to consider the overall architecture. It sounds to me like the API server is unnecessary and might actually be a bottleneck that will affect scaling and performance.

Depending on the architecture, you may have an event-driven paradigm or some other need that necessitates communication between micro services. This does not have to be REST based. You might look at using queues, messaging platforms like Kafka or gRPC.

The bottom line here is that your technical needs should drive the design.

Collapse
 
srishtikprasad profile image
Srishti Prasad

@phototrip_8f65aa1941692af Thank you for sharing your thoughts and for adding such valuable insights! The use case I described in the blog was meant to illustrate one approach and just differentiating their use and not suggesting, but you’re absolutely right.

Your suggestion to explore event-driven paradigms, queues, or messaging platforms like Kafka or gRPC for inter-service communication is spot on. These tools can indeed enhance scalability and performance, especially in systems with high concurrency or complex workflows.

Thanks again for contributing to the discussion! If you have any recommended resources or examples for designing such architectures, I’d love to hear about them. 😊

Collapse
 
sooraz2 profile image
Suraj Kunwar • Edited

Wait you created and named API server for microservice just to merge data/response from multiple microservice right?

But what if you have to get Order or User data? I guess you hit their own url (redirect API gateway).

Then I think you API server is just a another microservice you just complicate it by putting API Service (since this is used for some combine data case only)

Collapse
 
srishtikprasad profile image
Srishti Prasad

To get specific user data or order data ,
For straightforward, service-specific operations (like fetching order details or user information), the API Gateway can directly route requests to the respective microservices. The API Server comes into play only when there’s a need for:

  • Data orchestration: Combining responses from multiple microservices.
  • Complex business logic: Logic that spans across multiple services and would otherwise require clients to make multiple requests.
Collapse
 
srishtikprasad profile image
Srishti Prasad

Yes, the primary role of the API Server in this setup is to handle orchestration and aggregation for use cases where multiple microservices are involved. This approach abstracts the complexity for the client, providing a single, unified API endpoint. While this might seem like an added layer, it simplifies client-side interactions, especially for cases requiring combined or dependent data.

Collapse
 
srishtikprasad profile image
Srishti Prasad

In observing that the API Server can be seen as another microservice. However, its purpose is slightly different:

It acts as a middleware layer to manage cross-service interactions.
This design can improve modularity and simplify clients by offloading orchestration and verification logic to a centralized service.
In systems without an API Server, clients or the API Gateway might need to handle these responsibilities, increasing complexity in those layers.

Collapse
 
sooraz2 profile image
Suraj Kunwar

i) What if you have to update some data that makes changes to multiple services, so you use API Server in this case as well?

Or have to update data on some service what need to check/verify from other service, you use API server here as well?

Collapse
 
srishtikprasad profile image
Srishti Prasad

This is another key use case for the API Server:

  • For example, when updating an order status requires verifying user permissions or inventory availability, the API Server can handle these inter-service dependencies.
  • Without an API Server, these dependencies would need to be handled directly by microservices or pushed to the client, complicating the architecture.
Collapse
 
srishtikprasad profile image
Srishti Prasad

Great question! In scenarios where updating data involves changes across multiple services:

  • The API Server can orchestrate these updates, ensuring consistency and managing transaction-like operations across services.
  • Without an API Server, you might need to:
    • Implement such logic in the client (not ideal).
    • Distribute cross-service coordination among microservices themselves, which can lead to tighter coupling and complex interdependencies.

The API Server helps keep microservices loosely coupled by centralizing coordination.

Collapse
 
chetan_more_bb6c32cfcb360 profile image
chetan more

Thank you, easy to read and understand. Looking for more.

Collapse
 
srishtikprasad profile image
Srishti Prasad

You're welcome! @chetan_more_bb6c32cfcb360 I'm glad you found it helpful.

Collapse
 
leenattress profile image
Lee Nattress

Instead of a single API server or gateway, use a domain and map the path using base path mapping.

Have each path map to it's own API gateway for maximum decopling and seperste the http layer from the service layer.

Collapse
 
deadreyo profile image
Ahmed Atwa • Edited

What are API Gateways usually made with? Are they web servers like nginx or are they runtime services like Nodejs or Java?
Makes me wonder if API Server and Gateway could be merged

Collapse
 
srishtikprasad profile image
Srishti Prasad • Edited

@deadreyo Firstly, API Gateways can be built using different technologies depending on the requirements of the system.

  • Web Server-Based Gateways (e.g. Nginx, Apache)
  • Runtime-Based Gateways (e.g. Node.js, Java, Go, Python)

It’s technically possible to merge an API Gateway and an API Server, especially if you have a small or simple system. However, in most cases, keeping them separate is beneficial due to their distinct roles.
In small-scale applications or monolithic architectures, merging the API Server and Gateway could reduce the number of components to manage.

Collapse
 
deadreyo profile image
Ahmed Atwa

Can web servers manage the authentication and token verification? I assumed no and that a runtime is required for these, due to needing to do complex computations or using a library (for JWT for example), or query the database to verify the token's body is valid.

Collapse
 
vedesh_padal profile image
Vedesh Padal

It was thorough and detail, at least for me as a final year student trying to understand how things work in with complex business functionality and microservices.
Thanks!

Collapse
 
srishtikprasad profile image
Srishti Prasad

Thank you for the kind words! @vedesh_padal