New API Development Platform, join Blackbird Beta and try it now Learn More

Back to blog

Request-Driven (RESTful) vs Event-Driven in Microservices

Anita Ihuman
June 28, 2023 | 10 min read

As technology advances, so do the techniques and tools used for building applications. APIs have become increasingly prominent over the years, now widely used for exchanging data between two or more systems in the digital landscape.

Today, there are numerous ways to handle application integrations and develop APIs. However, two specific methods for enabling software communication in your project stand out: Event-Driven APIs and Request-Driven (RESTful) APIs.

While both approaches aim to achieve the same goals, their underlying architecture, data flow, and scaling techniques differ. In this article, we will explore the evolution of event-driven and request-driven (RESTful) APIs, their differences, and the benefits they offer. Finally, we will discuss when to use one over the other.

Evolution of Request-Driven (RESTful) Architecture

Developers started creating web services in the mid-2000s, employing RESTful microservice architecture (representational state transfer), which uses HTTP methods like GET, POST, PUT, and DELETE to communicate with services. This architecture was designed to support basic CRUD (create, read, update, and delete) operations.

RESTful web services soon became the de facto standard for building web APIs, with major companies like Facebook and other cloud-based applications leveraging RESTful architecture in their services.

In recent years, there has been renewed interest in evolving RESTful architecture to make it suitable for some modern-day applications. These efforts include adding support for WebSocket, using JSON-LD for semantic data, and GraphQL for more efficient data retrieval.

What are Request-Driven (RESTful) APIs?

Request-driven microservice architectures have a one-way, synchronous communication model with their clients. As a result, they must occur one at a time, in a predetermined sequence, and each interaction halts the process until it is completed, thereby leading clients to always refresh the API backend to retrieve the most up-to-date information.

Request-driven APIs also follow a model where clients communicate with servers via a request-and-response model. This means that a request has to be made by the client for a response to be provided by the server. So, if there is no request, there is no response.

To help you have a better understanding of how request-driven APIs work, let’s imagine we have a music streaming API that provides access to a library of songs, artists, genres, and albums. In this case, the API would include data retrieval endpoints like:

  • /songs
    to receive a list of all available songs
  • /top-artists
    to receive a list of all top artists available
  • /genre
    to receive a list of all available song genres
  • /albums
    to receive a list of all available albums

Requests to any of these endpoints could include optional parameters such as filtering by genre or songs. For instance, a request for all jazz songs could appear as follows:

GET https://mymusic.com/songs?genre=jazz
.

The API would then send back a

JSON
response with a list of all the songs that are categorized as “jazz.” The song title, artist, album, length, and a preview link could all be included in this response. However, the user will only receive a carefully curated list specific to the request they made.

Request-Driven (RESTful) microservices

Advantages of Request-Driven APIs

  • Language agnostic: The request-driven API allows developers to connect modular services written in different languages, regardless of the platform on which they run.
  • Flexibility: REST APIs are versatile in that they can return data in various formats, including JSON, XML, and HTML. This adaptability enables developers to select the format that best meets their requirements.
  • Platform independence: Since they use standard HTTP requests, clients can access them from any platform or device with an internet connection.
  • Cost-friendly: Development costs are reduced because upgrades are faster and easier.

Disadvantages of Request-Driven APIs

  • Poor user experience: Since most requests are processed on the server side, Request-driven APIs can cause an increase in traffic on backend servers, subsequently slowing response times.
  • High network traffic: Request-driven microservice architecture needs a request-response mechanism, meaning each client request creates network traffic. Hence, this leads to a lot of traffic on the network and problems with latency.
  • Limited scalability and functionality: Since they are stateless, each request is expected to contain all the information the server needs to complete the request. Hence, they may not be suitable for more complex business processes that require multiple interactions and actions.

Evolution of Event-Driven Architecture

Today's applications face an exponentially growing list of real-time events that must be captured and responded to meet user demands. These events range from human actions and command and control instructions to sensor readings and more.

EDA (Event-Driven Architecture) has become a key approach for building scalable, responsive, and resilient distributed systems. The need to handle increasing complexity, demands, and scale in modern applications has driven the evolution of EDA.

What are Event-Driven APIs?

In an Event-Driven microservice architecture, clients communicate with servers via a publish and subscription model. This usually involves asynchronous communication and uses events to trigger and communicate between decoupled microservices in near real-time, eliminating the need to poll for updates and status repeatedly.

All social media platforms today share a common goal: to make the user experience of their products seamless and keep users constantly engaged. These platforms achieve this by utilizing event-driven APIs to send notifications to their users. For instance, when initiated, Slack notifies you whenever a new activity or interaction occurs in a channel you belong to. If you are tagged in a discussion, you immediately receive notifications on your device about this action. Similarly, when you make a post on Twitter or LinkedIn, you’ll be notified when other users like and interact with your post.

All these interactions are designed so that users can engage with the software in real-time without constantly refreshing or reloading it.

An Event-driven API is focused on identifying, retrieving, and responding to events in real-time to provide better service, give customers a better experience, and help businesses make better decisions.

Event-Driven Microservices

Advantages of Event-Driven APIs

  • Increased Engagement: Event-Driven architecture makes it possible to process events in real-time, allowing applications to respond to user actions and system events promptly. This enhances the user’s experience and drives more engagement within the application.
  • Flexibility: Designed to handle multiple event sources and data formats, making it easy to connect to other applications and services.
  • Resilience: With EDAs, components can continue running even if other parts fail. Since components are not tightly connected, changes in one region don’t affect the others. Thus, errors in one part can be fixed without affecting the whole system.
  • Scalability: Can handle large volumes of requests without impacting performance, making them suitable for use in high-traffic applications. It eliminates the need for continuous polling for updates, so the application reacts only when necessary.

Disadvantages of Event-Driven APIs

  • Cost: Implementing an Event-Driven architecture can be more expensive than other architectures due to the additional infrastructure needed to handle events and responses.
  • Debugging and Troubleshooting: Debugging can be more challenging, as events can occur at any time and be triggered by multiple sources.
  • Complexity: EDAs can be more complicated due to the need for additional components to manage events and responses. Good event management is required to ensure events are handled correctly and the system runs smoothly.

Comparison of Request-Driven (RESTful) and Event-Driven Microservices

Request-Driven (RESTful) vs Event-Driven Architecture in Microservices

In some software development scenarios, it may be best to combine both approaches. While Event-Driven architecture allows components to communicate in real-time, handle large amounts of data, or update data in real-time, Request-Driven architecture might still be better for specific use cases, like authentication, where a request-and-response model is more suitable for handling security measures.

Conclusion

In conclusion, both Request-Driven and Event-Driven microservice architectures offer unique advantages and are often considered when building microservices applications. Although they perform different tasks, the system's specific needs and circumstances will determine which method to employ. However, a hybrid approach that combines RESTful and Event-Driven architectures can provide a more flexible and scalable solution for modern software design.

Simplified Kubernetes Management with Edge Stack API Gateway

Routing traffic into your Kubernetes cluster requires modern traffic management, and that’s why Edge Stack includes a modern Kubernetes ingress controller that supports a broad range of protocols, including HTTP/3, gRPC, gRPC-Web, and TLS termination.

Learn More about Edge Stack

Edge Stack provides traffic management controls for resource availability, enhancing the efficiency and reliability of services deployed within Kubernetes environments.