Building a modern platform for wireless order processing at Walmart
Source: https://pixabay.com/illustrations/personal-collective-group-knowledge-3286017/I am often presented with the question of whether orchestration should be used in a modern services architecture or if all integration needs to be through choreographed events. I’ve even had conversations with architects who believe orchestration has no place in modern microservices architectures. If you read some of the technical literature out there, you may start to believe this yourself. Well, I can confidently say this is simply a myth. The reality is some business problems are best served by hybrid approaches where both orchestration and choreography need to be used. The trick is knowing when to use which approach and how to deal with the complexities they bring.
Like anything related to architecture design, deciding between orchestration, choreography, or both is a “it depends” answer. So then how do you choose? For starters, you need to have a very deep understanding of the business problem being solved including the complexities of the underlying processes, have measurable business outcomes (in other words, what does success mean — and not the fluffy stuff), and know how/when/where to allow design complexity. To illustrate this, I’m going to detail how orchestration and choreography can be used together. This won’t be theory, I am going to use an architecture I’ve implemented at Walmart which has survived its initial launch, scaled without any issues, and is being extended via the next wave of business transformation. Let’s get to it.
Problem Statement
Before I can talk about why certain choices were made, I need to explain the business problem. The overall problem needing to be solved was transforming a legacy wireless order processing system which had become complex and brittle over time. It was no longer able to scale to higher volumes, could not be changed to meet new business needs, and was too costly to maintain. To make things even more complex, the new system had to support ecommerce and in-store sales channels which meant it was direct consumer facing and would be used by associates in retail stores. From an architecture perspective the legacy system had many challenges. Services lacked properly defined boundaries, there were numerous data silos, designs were brittle and complex, and it was built on what was then an outdated tech stack. Last but not least, it was deployed in a data center which was being shut down and needed to be moved to the cloud. This was a classic case of a system that served its purpose well at one point, however new business needs exceeded what this architecture was originally intended to provide and it needed to be transformed. Years of technical debt mounted and the logical go forward investment was to rebuild and modernize it.
Before we get into the solution details let’s talk about the overall business vision. The business wanted a platform which could, of course, support their current needs of processing wireless orders but also needed one which could support order processing for different products. Having point solutions for each product was not a viable option and would result in far more complexity and cost than desired. Obviously we couldn’t design for what we didn’t know, however, we also knew the importance of understanding where the business wanted to be in order to create the right foundational architecture. Order processing in our domain, regardless of product type, shared a common set of business capabilities; the core architecture objective was to build a reusable and extensible platform that could sustain growth to enable multi product order management.
Architecture Solution
Now let’s take this down another level. There were several important factors about the business processes which were core inputs into the solution design:
- The order process spanned several business domains and contained well-defined process flows for all normal paths. Some exception paths were well-defined but there were a number of use cases that did not follow a strict path and therefore needed processing flexibility, especially in the case of retail sales.
- Processing wireless orders was complex, involved many steps, and required numerous interactions with external third party systems. Some of these interactions are highly responsive while others take longer. To make things more interesting, latencies on these interactions can vary so the solution needed to accommodate different types of characteristics on a transaction-by-transaction basis.
- The business wanted near real time insights into transactions (orders) as they were taking place. Additionally, there were explicit business events which needed to be tracked and available for operational insights. These were especially important during sales, promotions, and holiday events where the business needed to see sales volume and track process status as orders were taking place.
- Any glitch in the process, whether a business or technical exception, meant a loss of sales. Tracking every processing step and the state of each order in an easy way were essential. Also, there was very, very little tolerance for data loss. Simply put, when an order reached a certain state and was paid for, data must not be lost. No exception at any level including a full disaster recovery event, could result in a data loss.
There’s alot to unpack in this list. Before you read further, take a second look at the items above and study them. Each item fed directly into how the architecture was built and how trade-offs were made. We compared and analyzed different ways to manage orders, had some hefty discussions, and ultimately landed on the following key architecture facets:
- The end-to-end order process would be orchestrated by a business process management (BPM) engine which would be in the bounded context of the core business service. This service, Order Processing Service, would be responsible for taking a wireless order through its required steps, emitting business events along the way, and would be the single system of record for the order state at any point in time. In other words, its job was to orchestrate business processes and respond to choreographed events. The decision to use a BPM engine was due to the strict requirements to manage each order through a series of steps, to provide a way to quickly make workflow changes, and to provide near real time operational views as each order was being executed. The Order Processing Service was decidedly a miniservice and great care was taken in how the workflows and subflows were designed to achieve the flexibilities needed.
- Events were divided into two types; macro events which were events needed to manage order state and drive workflow processing by the BPM engine and micro-events which were events used to choreograph finer grained activities between domain services which were subordinate to the core flow.
- Domain services, which are all the services in the same business domain needed when processing orders, would be solutioned as mostly microservices. Each supporting service had a specific responsibility, would be free to use additional technologies to fulfill their portion of the order processing (e.g. a rules engine, a sub-workflow), would not maintain order state, and would be responsible for informing Order Processing Service when it completed work using events or API callbacks if asynchronous processing was used or, if synchronous was used, it would be immediate as the calls were blocking. Where needed, domain services would be able to create their own micro-events and communicate directly with one another for micro-flows without having to go through the Order Processing Service.
- Enterprise integrations would all be choreographed through synchronous APIs because they were a part of the core BPM flow, connected directly to the customer journey, and attached to the user experience layer. There were also critical service level agreements (SLAs) which had to be tightly managed.
- Business data, including order state, would be stored separately from workflow operational data and both would be within the boundary of the Order Processing Service. Order state data was maintained as business data and separate from other workflow operational data.
- Data would flow to the data warehouse based on events which the business wanted to consume for analytics and to monitor transactions. Other transactional data would be available in the warehouse on a near real time basis. The requirement was to have data available in the warehouse within minutes (think 1–3, not 5–10). This velocity tolerance was a significant factor when it came to deciding when and where to use orchestration, choreography, and determining event granularity.
Below is what the architecture looked like at a logical level with all of the components described above laid out.
Some Challenges
This architecture is not without its complexities. Here are some of the things that came up during its implementation which we had to address:
- Statement management for processing steps implemented using choreographed service interactions. While there was decisiveness as to what was a macro vs mini-event, managing state so that it can be easily determined at any point in time is made easier with BPM but the mini-events will also need to be tracked and not lost.
- How to effectively draw the line between the core business flow and both sub-flows and mini-flows that execute portions of the process independently. While things may happen outside the core business flow, we needed to know exactly where an order was in its lifecycle at any point.
- Related to the above item, deciding on the granularity of events is important. We started with what was needed to drive the orchestration and slowly created finer grained events to enable choreographies and execution of mini-flows. There needs to be a relationship between macro events and mini events.
- Handling of retry logic, exceptions, timeouts, and user experience management for long running transactions. In short these items are the complex non-happy path scenarios which need to be thought through and modeled. In this architecture nearly all were handled by Order Processing Service. However there would be cases, particularly where there were long running transactions and choreographies, some of this logic would be implemented by domain services. Deciding where compensating transactions would be needed, ensuring idempotency of services, and leveraging state management all became techniques we had to introduce over time.
- Data velocity for analytics. Generally speaking data should move as fast as it can to reporting and analytical layers, unless it’s being consumed from event streams directly and have necessary details. However, when data is dispersed across microservices, stitching together a consumable data set can be complex.
Summing It Up
So there you have it. There may be some who say this is not a “pure” modern service architecture and choreography should have been used without any orchestration. I beg to differ and would offer a lesson — build the simplest solution your business needs by being practical. Don’t take on complexities you don’t need to and don’t assume theory reflects reality. Agile architecture means starting simple, evolving, and shaping the best solution iteratively. Choreography and orchestration can absolutely work together and if they are the right tools for the problem, go for it.
Microservices with Orchestration and Choreography was originally published in Walmart Global Tech Blog on Medium, where people are continuing the conversation by highlighting and responding to this story.
Article Link: Microservices with Orchestration and Choreography | by Navdeep Singh | Walmart Global Tech Blog | Aug, 2021 | Medium

