DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • The Bill You Didn't See Coming
  • Versioning Lies: A Date Contract Is a Promise That Never Breaks
  • MCP Elicitation: Human-in-the-Loop for MCP Servers
  • Efficient API Communication With Spring WebClient

Trending

  • Using LLMs to Automate Data Cleaning and Transformation Pipelines
  • Offline-First Patch Management for 10,000 Edge Nodes: A Practical Architecture That Scales
  • Exactly-Once Processing: Myth vs Reality
  • The Agentic Agile Office: Streamlining Enterprise Agile With Autonomous AI Agents
  1. DZone
  2. Data Engineering
  3. Databases
  4. Chopping the Monolith in a Smarter Way

Chopping the Monolith in a Smarter Way

In this post, I offer another alternative to chop the monolith. Instead of forking the call on the client side, we fork the call on the Gateway side.

By 
Nicolas Fränkel user avatar
Nicolas Fränkel
·
Nov. 30, 23 · Analysis
Likes (2)
Comment
Save
Tweet
Share
1.9K Views

Join the DZone community and get the full member experience.

Join For Free

In my previous post Chopping the Monolith, I explained that some parts of a monolith are pretty stable and only the fast-changing parts are worth being "chopped." I turned the post into a talk and presented it at several conferences. I think it's pretty well received; I believe it's because most developers understand, or have direct experience, that microservices are not a good fit for traditional organizations, as per Conway's Law.

In the talk, I use an e-commerce web app as an example.

e-commerce web app

The pricing needs to change often due to business requirements, and it is a good candidate for chopping. The idea is first to expose pricing as an HTTP route.

HTTP route

At this point, we can configure the Gateway to forward pricing calls with the cart payload to another component, e.g., a FaaS.

configure gateway

I expected a lot of pushback because we now need twice the number of HTTP calls. Given that the client is remote, it has a non-trivial performance cost. It has yet to be mentioned, but I'd like to offer another better-designed approach today.

In particular, we can move the forked calls from the client to the API Gateway. We still have twice the number of calls, but since the Gateway is much closer to the upstream(s), the performance hit is much lower.

No one will be surprised I'm using it for my demos. It implements a plugin architecture and comes bundled with plugins that address most possible requirements. We need a plugin that pipes an HTTP call's output to another HTTP call's input. It's not part of the current out-of-the-box plugin portfolio; however, when no plugin fits your requirement, you can develop your own - or find one that does. My colleague Zeping Bai has developed such a plugin:

When handling client requests, the plugin will iterate through the nodes section of the configuration, requesting them in turn.

In the first request, it will send the complete method, query, header, and body of the client request, while in subsequent requests it will only send the last response with the POST method.

The successful response will be recorded in a temporary variable, and each request in the loop will get the response body of the previous request and overwrite the response body of the current request.

When the loop ends, the response body will be sent to the client as the final response.

— apisix-pipeline-request-plugin README

The final sequence is the following:

final sequence

Note that the apisix-pipeline-request-plugin consumes the input. As we want to return all the necessary data, we must return both the cart lines and the price in the payload. The pricing should return the cart lines, which is not an issue since it receives it as an input.

Apache APISIX Configuration

The Apache APISIX configuration is the following:

Route URI Plugins Comment
#1 /* Catch-all route for front-end resources
#2 /api* proxy-rewrite
  • Catch-all route for back-end API calls
  • The plugin rewrites URIs to remove the /api prefix
#3 /api/checkout pipeline-request The magic happens here:
  • The first pipeline node calls the monolith to return the cart lines
  • The second calls the pricing component with the cart lines to return the cart lines and the pricing computed in the component
#4 /api/price azure-functions I implement the pricing in an Azure FaaS, but it's an implementation detail

Conclusion

In this post, I offer another alternative to chop the monolith. Instead of forking the call on the client side, we fork the call on the Gateway side. While Apache APISIX doesn't offer such a plugin out-of-the-box, the community fills in the blank with the apisix-pipeline-request-plugin.

Compared to the original solution, this alternative has a couple of benefits:

  • Better performance, as the fork happens closer to the Gateway
  • No impact client-side

The complete source code for this post can be found on GitHub.

To Go Further

  • Chopping the monolith, the original way
  • apisix-pipeline-request-plugin
  • Chaining API requests with API Gateway
API Requests

Published at DZone with permission of Nicolas Fränkel. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • The Bill You Didn't See Coming
  • Versioning Lies: A Date Contract Is a Promise That Never Breaks
  • MCP Elicitation: Human-in-the-Loop for MCP Servers
  • Efficient API Communication With Spring WebClient

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook