Sub topic 5
What a middleware layer adds
This chapter assumes you know basic Salesforce objects and records, can read REST and JSON, and have seen a simple integration between two systems. It explains what a middleware layer does that Salesforce does not do natively. Later chapters cover when to choose it.
What middleware is
Middleware is a runtime that sits between systems and handles the work of connecting them. Salesforce, an ERP, a payment service, and a legacy database each talk to the middleware. They do not talk directly to each other. MuleSoft's Anypoint Platform is one example.
The functions it provides
| Function | What it does | Example |
|---|---|---|
| Transformation | Converts data between formats and field names | ERP JSON to Salesforce Account fields |
| Orchestration | Runs several calls in order as one business step | Check stock, then reserve, then confirm |
| Routing | Sends a message to a target based on its content | Orders over a set value go to an approval service |
| Protocol mediation | Bridges different protocols | Salesforce sends REST, the legacy system expects SOAP or a file drop |
| Security | Applies authentication, policies, and secret handling in one place | Rate limits and OAuth enforced at the gateway |
| Monitoring | Records traffic, errors, and latency across systems | One dashboard for every integration |
Transformation in practice
Mapping logic is the most common reason teams add middleware. Without it, the mapping lives in Apex or Flow inside Salesforce. Each new consumer then needs its own copy.
%dw 2.0
output application/json
---
payload map (customer) -> {
Name: customer.company_name,
BillingCity: customer.address.city,
External_Id__c: customer.id
}This runs in the middleware. If the external system renames company_name, you change one mapping. You don't deploy Salesforce metadata.
Orchestration and routing
A native Apex callout handles one request and one reply well. Compare that to this sequence: read an order, look up the customer in the CRM, call a tax service, write to the ERP, and undo the earlier steps if one fails. Salesforce can do it, but it has to handle transaction limits, callout limits, and partial failure in code. Middleware runs the whole flow outside Salesforce and keeps the state of each step.
What changes for Salesforce
Salesforce keeps one connection, to the middleware. The Named Credential then points to one stable endpoint instead of many.
HttpRequest req = new HttpRequest();
req.setEndpoint('callout:Middleware_Credential/orders/' + orderId);
req.setMethod('GET');
HttpResponse res = new Http().send(req);The Apex is as simple as before. The complexity moved into the layer behind that endpoint.
What it costs you
Middleware adds a runtime to operate, a skill set to hire for, and licensing cost. It also adds a hop, which increases latency and creates one more place for failure. A middleware layer that only forwards a request unchanged adds those costs and no benefit.
Summary of the added value
- One place for mapping, so field changes do not spread across systems.
- Flows that span many systems and recover from partial failure.
- Support for protocols Salesforce does not speak natively.
- Shared security policies and a single view of traffic and errors.
Exercise
A team maintains the same customer field mapping in Apex, in a Flow, and in a nightly script. Which middleware function would remove this duplication, and where would the mapping live afterward?
Show answer
Transformation. The mapping would live once in the middleware, for example as a DataWeave script. Salesforce and the other consumers would call that layer instead of keeping their own copies.
Exercise
Name two costs that middleware adds even when it works perfectly.
Show answer
Any two of: an extra runtime to operate, licensing cost, specialized skills, and added latency from the extra hop with one more point of failure.