ERPClimb logoERPClimb
Remote services and resilience
SAP Cloud Application Programming Modelintermediate 5 min read

Remote services and resilience — SAP Guided Tutorial

Free sample lesson · open to everyone

Key takeaway

Consuming SAP S/4HANA and other OData APIs from CAP: importing the API definition, binding it through BTP destinations, mocking it locally, and designing timeouts, retries and caching so a slow backend does not take your app down.

In this lessonShow sections

Visual overview

Remote services and resilience — learning sheetFlow: cds import: API model → Destination: credentials → cds.connect.to: query → Resilience: timeout, cache. Key ideas: IMPORTING AND CONFIGURING; DELEGATING REQUESTS; CONNECTIVITY; RESILIENCE PATTERNS. Watch out: Calling the remote system on every READ couples your availability and latency to the backend — cache, replicate or degrade gracefully.ERPClimb.com / CAP / LESSON 8/12 / LEARNING SHEETRemote services and resilience1 · HOW IT FLOWS1cds importAPI model2Destinationcredentials3cds.connect.toquery4Resiliencetimeout, cache2 · KEY IDEAS EXPLAINEDImporting And ConfiguringDownload the EDMX from SAP Business AcceleratorHub or the system's $metadata, then `cds import<file>`.Config: `"API_BUSINESS_PARTNER": {"kind": "odata-v2","model"…Delegating RequestsDelegate reads of the projection: `this.on('READ','Suppliers', req => bp.run(req.query))`.CAP translates the CQN to OData query options forthe remote service.ConnectivityCloud: the Destination service stores URL andauthentication (OAuth2SAMLBearer, basic, clientcredentials).On-premise: Cloud Connector + Connectivityservice; destination type OnPremise.Resilience PatternsSet timeouts; never let a request hang on thebackend indefinitely.Retry only idempotent reads, with backoff; neverblindly retry creates.3 · REMEMBER · WATCH OUTRemember`cds import API_BUSINESS_PARTNER.edmx` creates a CDS model of theremote API under srv/external.In package.json, cds.requires.<name> declares kind(odata-v2/odata), model and credentials (usually a destination name).`const bp = await cds.connect.to('API_BUSINESS_PARTNER')` then`bp.run(SELECT.from(...))` sends OData requests.!Watch outCalling the remote system on everyREAD couples your availability andlatency to the backend — cache,replicate or degrade gracefully.4 · IN A REAL PROJECTA supplier portal showed supplier names by calling S/4HANA once per row. When S/4HANA slowed during month-end,the portal timed out entirely. Batching the keys into one remote call, caching names for 15 minutes andshowing IDs when the backend was unavailable kept the portal usable during the next close.Original ERPClimb learning sheet • Verify against your SAP release and edition

The situation: a real project scenario

A supplier portal showed supplier names by calling S/4HANA once per row. When S/4HANA slowed during month-end, the portal timed out entirely. Batching the keys into one remote call, caching names for 15 minutes and showing IDs when the backend was unavailable kept the portal usable during the next close.

Explanation

Most real CAP applications eventually need data they don't own, typically from SAP S/4HANA or another OData API. The process starts by importing the remote service's metadata — downloading the EDMX from the SAP Business Accelerator Hub or the target system's $metadata endpoint, then running cds import <file>, which generates a CDS model of the remote API under srv/external.

That remote service is then configured in cds.requires, naming its kind (odata-v2 or odata), its generated model, and its credentials, which in production usually means pointing at a destination name rather than a hardcoded URL, for example "[production]": { "credentials": { "destination": "S4_BP" } }.

From there you expose only the fields you actually need through a projection, such as entity Suppliers as projection on bp.A_BusinessPartner { key BusinessPartner as ID, BusinessPartnerFullName as name }.

To actually serve data, you delegate: const bp = await cds.connect.to('API_BUSINESS_PARTNER') gives you a handle to the remote service, and a handler like this.on('READ', 'Suppliers', req => bp.run(req.query)) forwards the CQN query, which CAP translates into the equivalent OData request options for the remote system.

One important limitation is that joins between a local entity and a remote one don't happen in the database — the usual pattern is to fetch the relevant keys locally, then issue a single remote call for all of them, rather than calling the remote system once per row, which is the remote equivalent of the N+1 problem.

Locally, the remote service can be mocked with sample data so development doesn't depend on a live backend connection. In the cloud, the Destination service supplies the URL and authentication — OAuth2SAMLBearer, basic auth, or client credentials — and for on-premise systems, the Cloud Connector plus the Connectivity service bridge the network gap, using a destination of type OnPremise. Where the remote system's own authorization needs to reflect the actual end user rather than a generic technical user, principal propagation carries that user's identity through to the backend call.

Because your app's own availability is now coupled to a system you don't control, resilience has to be designed in rather than assumed: set explicit timeouts so a slow backend can't hang your request indefinitely, retry only idempotent reads with backoff (retrying a POST that creates a document risks creating duplicates), and cache or replicate slowly changing data so a temporary outage degrades gracefully instead of taking the whole feature down.

Hands-on steps: import API_BUSINESS_PARTNER and expose a Suppliers projection; run it locally against mocked data and inspect the OData request CAP generates in the logs; configure a real destination and run in a hybrid profile against a sandbox system; then simulate a slow backend and confirm your timeout and error handling actually kick in. The goal is that when the remote system is unavailable, your app returns a controlled error within your own timeout, and the rest of the app keeps working.

Code example

ABAP Code
// srv/supplier-service.jsmodule.exports = cds.service.impl(async function () {  const bp = await cds.connect.to('API_BUSINESS_PARTNER');  this.on('READ', 'Suppliers', req => bp.run(req.query));});

Watch out

Common mistakes

  • Hard-coding backend URLs and credentials instead of using destinations.
  • Reading the remote API once per row of a local list (remote N+1).
  • Retrying POST requests that create documents, causing duplicates.
  • Using a technical user where the backend needs the business user's authorization.

Do this

Best practices

  • Project remote entities down to the fields you use.
  • Use destinations and principal propagation where backend authorization matters.
  • Define timeout, retry and fallback behaviour explicitly for every remote dependency.

In the interview

Interview angle

Interviewers look for the full chain — cds import, cds.requires config, destinations and Cloud Connector, delegating CQN — and then for resilience thinking: timeouts, safe retries, caching or replication, and principal propagation when backend authorizations apply.

Practice this lesson

Original educational case studies for SAP consultants, not official SAP certification exam questions. Verify product edition and implementation details against the current SAP documentation.

Quick check

0 of 4 questions attempted

Question 1 of 4

What does `cds import API_BUSINESS_PARTNER.edmx` do?

Practise this in an interview

Answer in your own words and get instant feedback, the way an interviewer would judge it.

1How do you consume an S/4HANA OData API in CAP and make it production-ready?

2When would you replicate S/4HANA data into your CAP app instead of reading it live?

Was this lesson helpful?

Keep exploring

Check before use: lesson examples are educational, not a guarantee of correctness for your SAP edition or release. Sample code has not been executed on your SAP system. Confirm API availability, syntax, authorizations and business impact in an approved development or test environment.