Architecture Decision for Choosing Right Digital Integration Patterns – API vs. Messaging vs. Event

IT environments and application portfolios are growing rapidly, and they are fundamentally hybrid in nature. Due to the growing need to connect heterogeneous applications on hybrid cloud, in various locations and by different service providers, there is a need for using robust and fit-for-purpose integration techniques. Direct APIs (e.g. Rest, gRPC), Messaging, and Events are the most common integration choices for digital applications. While making these important architectural choices, often organizations and practitioners take an extreme stand towards one or the other of these integration patterns. However, it is not the question of whether to use Direct API, Messaging, or Event, but it is more a question of when to use each of these integration Patterns.

Problem Statement

The three integration patterns (Direct API, Messaging, and Events) are important for modern applications. However, it is often a challenge for designers and developers to determine the integration option best suited for different scenarios and the implications of the choice of integration. In the section below, we provide a guiding framework to help make this decision better based on the context of the integration and organizational factors

A Closer Look at API, Messaging, and Event-Based Integrations

Direct API 

Direct Application Programming Interface (API), allows two heterogeneous applications to talk to each other. For example, each time we use an app on our mobile devices, the app is likely making several API calls to various digital services.

Direct APIs can be designed to be Blocking (Synchronous) or Non-Blocking (Asynchronous). Of these, Non-Blocking APIs are preferred to ensure resources are not blocked when the consumer is waiting for a response from provider. Non-blocking APIs also help create independently scalable integration model between API Consumers and API Provider

Figure 1- Non-Blocking API Call

Figure 1- Non-Blocking API Call


Strengths

Weaknesses 

One can argue that Blocking APIs (synchronous APIs) are not highlighted here. However, any Direct API can be designed to be blocking or non-blocking calls, but that needs to be considered during design time with a strong preference to non-blocking APIs

Messaging

A Message is fundamentally an asynchronous mode of communication between two applications — it is an indirect invocation, such that two applications do not directly connect to each other. Thus, the Messaging technique decouples the consumer and provider, and removes the need of provider being available at exact same point in time as the consumer. It also addresses the scalability limitations of the provider. For example, your legacy system can take only 100 requests per second and it cannot dynamically scale, message-based integration will, at a minimum, ensure it does not crash even when it gets 200 requests (significantly higher) per second.

Figure 2 – Messaging based integration

Figure 2 – Messaging based integration


Strengths

Caution

Event

Event depicts the occurrence of business activity. Any number of interested and authorized parties (services) can subscribe to the event and take the appropriate action in response to the event. Events can occur as a continuous stream when business events continue to happen, like currency exchange rate change as an event. By taking advantage of this continuous stream, applications can react immediately and also reason about the future based on what happened in the past.

Figure 3 - Event-driven integration

Figure 3 - Event-driven integration


For example, most financial organizations have been leveraging events based integration, in the domain of high-value transactions so they can be used by multiple systems for analysis of fraud, anti money laundering, and compliance analysis.

Strengths

Weaknesses

In addition to these integration modes, we must acknowledge that whole Industry is trying to move away from monolith applications into modular applications (if not microservices architecture) and distributed transaction management. With emergence of distributed transactions, need for event driven architecture and patterns for managing distributed transactions is gaining a lot of attention.

Event-driven solutions can also exploit serverless computing for zero operations, for details refer to our publication on "Emerging Patterns for Serverless Computing."

API vs. Messaging vs. Events – Comprehensive Decision Guide

Criteria

Direct API

1:1 Messaging 

Event based Mesaging 

Participating Applications

One to One

One to One

One to Many

Consuming Organization - Internal or External

Preferred for interactive or partner applications and to expose public facing interfaces.
Generally, industry-standard alignment of APIs is better, which is important for external integrations.
 Even for simple internal integrations API may be preferred — considering other factors in this table

Good for internal applications/services that will benefit from decoupled interactions

It is good for internal communications that will benefit from decoupled interactions, such as services defined on event-driven architectures.
 It is also good for certain external streams processing, if there is a need of high-frequency interface for continuous feed of data — such as IoT, Webclicks or key business events

Push versus Pull scenario (Just in time or ahead of time)

Efficient for “Pull” of the information when needed (on-demand)

Efficient for Push, publishing information as soon as it is available; usually to one consumer

Efficient for Push, publishing information as soon as it is available; usually too many consumers

Availability

Requires API provider to be available exactly at the time request is made. 

Does not require the provider to be available exactly at the time request is made. Even in real-time transactions momentary downtime can be tolerated without a big impact. 

Does not require the provider to be available exactly at the time request is made. Even in real-time transactions momentary downtime can be tolerated without big impact. 

Resiliency

Tight coupling requires the provider to be available exactly at the time the consumer invokes API. Need to employ resiliency patterns like circuit breaker, retries, timeouts to handle provider issues gracefully

Does not require provider to be available at exact same time - Momentary availability issues will not have severe impact (although overall response time will be impacted for an online request).
 Messaging can also be used to provide Load Levelling for APIs - Use a queue that acts as a buffer between a task and a service that it invokes in order to smooth intermittent heavy loads.

Does not require provider to be available at exact same time - Momentary availability issues will not have severe impact (although overall response time will be impacted for an online request)

Health Endpoint Monitoring - Strong platform support available that can be extended for functional checks

Health Endpoint Monitoring - Strong platform support available that can be extended for functional checks

Health Endpoint Monitoring - Strong platform support available that can be extended for functional checks

Performance

For a strictly sequential flow, API will provide relatively better performance (but the overhead of messaging or event should be in microseconds if configured rightly)

Although for sequential flow, it will add overhead generally in the microseconds range.     

Although for sequential flow, it will add overhead generally in the microseconds range. But for parallel processing it can improve performance - one published event can be picked up by many services instantly to perform different actions (compared to API where consumer will need to invoke each service and wait for acknowledgement)

Sequential versus Parallel processing (e.g. within a transaction processing)

Using Non-Blocking APIs parallel processing can be achieved 

Enables Parallel processing

Enables Parallel processing

Transaction Scenarios - ACID

API is best Suited to support ACID transaction scenarios and provide continuous consistency

It does not support immediate consistency transaction scenarios

It does not support immediate consistency transaction scenario

Transaction Scenarios - Distributed Transactions

Simple Transactions not involving many interactions between different applications
 API is not well-positioned to cater to requirements for complex distributed transactions, such as SAGA pattern

Messaging provides eventual consistency. Messaging is suited for Simple and Medium complexity transactions

This is well suited for eventual Consistency. This makes events best suited for Distributed transaction management and implementation of distributed transactions such as SAGA Pattern

Operational Complexity

Relatively easy. Dynamic scaling that can be configured and optimized for performance as the volume grows. 

Medium - Scalability need to be defined upfront considering expected loads for next couple of years.

Relatively higher. Scalability need to be defined upfront considering expected loads for next couple of years. Managing and optimizing event infrastructure for high performance requires deep understanding of Platform. 

Governance of Interface lifecycle

API Lifecycle needs to be managed; many products provide strong support for end to end API Lifecycle management.  

Message interface needs to be evolved on same lines however relatively limited support is available for its lifecycle management in most tools

Message interface needs to be evolved on same lines however relatively limited support is available for its lifecycle management in available tools

Evolution of Interface definition

Interface definition can evolve over time. Additionally, Graph QL for API provides great flexibility for consumers to ask exactly for what it needs an nothing more. This concept can also be extended to achieve version-less API

 Schema Evolution is feasible, for example with Avro, providing ability to evolve schema over time. However, every consumer gets complete Message details. 

 Schema Evolution is feasible, for example with Avro, providing ability to evolve schema over time. However, every consumer gets complete event details 

Onboarding of new Consumers

Consumers onboarding need to be governed, and it will create additional load for API Provider that need to be Managed (hopefully it is configured for on demand scaling)

Consumers onboarding need to be governed, and it will create additional load for Interface Provider that need to be Managed (hopefully it is configured for on demand scaling)

Consumers onboarding need to be governed. However, it will not create any additional load for Event Provider.

Key Takeaways

Common Mistakes

 

 

 

 

Top