Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
Martin-Pankraz
Active Contributor








This post is part of a series sharing service implementation experience and possible applications of SAP Private Link Service on Azure.

Find the table of contents and my curated news regarding series updates here.

Find the associated GitHub repos here.

Dear community,

Continuing with the implementation journey of SAP Private Link Service (PLS) for Azure we will have a closer look at connecting privately to the fully managed Azure Cosmos DB (Cosmos DB) using the Microsoft backbone.


Cosmos is a fully managed NoSQL and relational database for modern app development. It offers single-digit millisecond response times, automatic and instant scalability, along with guaranteed speed at any scale. Business continuity is assured with SLA backed availability and enterprise-grade security.

We are talking single digit millisecond response times 🤯 Why is this interesting?

The inherent capabilities of Cosmos DB enable use cases like real-time in-stock availability-check powered by massive marketing campaigns or black swan events. Imagine a web shop offering nearby store insights per product. Toilet paper in 2020 anyone? You really don’t want millions of users hitting your SAP system madly checking for remaining stock of the precious good. A controlled push of the stock data from your ERP or directly from the point-of-sales to Cosmos DB protects the SAP backend and gives the end-users on the web shop the valuable insight and experience they expect. At least if there is any toilet paper left 😉.

The described pattern builds upon the joint Microsoft + SAP intelligent routing story published on the SAP Discovery Center. You have a choice between Azure Traffic Manager (DNS based) and Azure Front Door (global routing, web-application Firewall, DDOS etc) for the end-user facing frontend app. Learn more about the different options here.

This post focuses on the Private Link setup and app development and does not repeat the high-availability and failover concepts discussed in the mentioned SAP Discovery Center mission. Read more about architecture topology implications here.


Fig.1 Architecture overview for distributed BTP apps and data backbone fed from Point-of-Sales and blended with S4 insights

Cosmos DB joining the SAP Private Link party completes the spectrum of database offerings for modern app development on SAP Business Technology Platform (BTP). This post discusses Azure Cosmos DB for NoSQL in a multi-region setup with provisioned throughput. Learn more about Azure IoT using Cosmos DB here.

To get started, create an instance of Cosmos DB through an ARM template, terraform, bicep, or the Azure portal. I will always reference the portal for a more visual flow.

Click, click, ready to reach for the stars with Cosmos DB and beyond



Consider the limitations of the free tier for your scenario. I would use it if I were you 😉


Select geo-redundancy to deploy automatically into the paired region of your primary Cosmos DB location (west + north Europe and vice versa for instance). You may add additional regions next.

Consider multi-region writes in light of your concurrency model. Otherwise choose “disable” to allow writes only to the primary region. Regarding the SAP inventory offloading scenario it might make sense to write only to the Cosmos DB instance close the SAP source and have only Cosmos DB read replicas transmitted to the other regions where your end-users are.


Ensure to retain access to the Cosmos DB UI via the Azure portal as highlighted above. Otherwise, you can only interact via APIs from the selected VNets or Firewall exceptions.

Inject your Cosmos DB instance into the private VNet of your choice or create a new one to finish the data base provisioning.

Once provisioned, easiest way to get started is to use the Cosmos DB demo data set.


Next, we will create the connection from BTP.

Privacy please!


Let’s prepare the SAP Private Link from the BTP Cockpit to connect with Cosmos DB in our multi-region scenario and name it “cosmos-pls” to match the associated NodeJS example app config. Navigate to your BTP subaccount and create a new instance as below:


Collect the required resource ID via CLI, Azure portal properties pane, or my favorite way: The JSON view from the overview pane. Choose Sql as subresource, because we are utilitzing the NoSQL API. Find the settings for the other flavours here.


Identify the technical names of your target regions via Azure Cloud Shell with command:
az account list-locations -o table

Start your region exploration from the Microsoft docs. Finish the create process on BTP and approve the connection request on your Cosmos DB instance on Azure to “seal the deal” 🫱🏾‍🫲🏽.


Remember from the beginning of our journey: to bind to the SAP Private Link deploy at least one app with service binding. So, let’s deploy our NodeJS app 😊

Head on to your IDE of choice and clone the repos. I am showing my steps and screenshots from SAP Business Application Studio:
git clone https://github.com/MartinPankraz/sap-nodejs-on-cosmosdb-app.git
cp templates/.env app


  • Maintain your Cosmos DB credentials in the `.env` file

  • From Cosmos DB UI navigate to: Settings -> Keys -> read-write Keys -> Primary Key

  • Verify your service name and define subdomain name under routes.



Run the app locally to make sure everything is in order. By the way, once you created the private link service binding, you may also test locally with 'cf ssh'. Learn more about that here.
cd app
npm install
npm start

Deploy to BTP to finish the SAP Private Link service binding.
cf push

You can verify by checking if the “View Credentials” button is now active (see screenshot below).

Collect the hostname for your SAP Private Link from the BTP service or from your Cosmos DB instance on Azure and maintain it on the ‘.env‘ file if not already done.


Ok, we are ready to run our first app instance - meaning our cf app using private link to reach primary Cosmos DB. Onwards to the code to see what happens🏄🏽

Leverage the Azure SDK for Cosmos DB for native SQL calls from BTP


At this point there is no support by Core Data Services (CDS) in SAP Cloud Application Programming (CAP) model for Cosmos DB yet. But there is a community thread on GitHub with the awesome SAP Mentors considering the PostgreSQL API of Cosmos DB or fully blown integration. Any updates vobu? Anyways stay tuned 🎶

Until then, we need to rely on the Azure SDK for Cosmos DB for NodeJS when developing our BTP apps. See below snippet selecting all addresses from the Cosmos DB sample data set with embedded SQL.
// Get all addresses from SampleDB. See more examples here: https://learn.microsoft.com/azure/cosmos-db/nosql/quickstart-nodejs?tabs=azure-portal%2Cwindows
fastify.get('/addresses', async (request, reply) => {
fastify.log.info(`Querying container:\n${CONTAINERID}`)

const { resources: results } = await client.database(DATABASEID).container(CONTAINERID).items
.query({
query: 'SELECT * FROM c'
})
.fetchAll()

for (const queryResult of results) {
let resultString = JSON.stringify(queryResult)
fastify.log.info(`\tQuery returned ${resultString}\n`)
}
reply.send(results)
})


As per Christian Lechner’s recommendation I changed the web server from Express to Fastify for a leaner experience and faster startup times. #Kudos to lechner for contributing 😊

Find the complete app on GitHub as always.

Complete the scenario by spinning up another CF subaccount in your desired secondary region, create the SAP Private Link, approve the additional connect request on Cosmos DB and deploy the second instance of your app. As mentioned before, have a look at the jointly published intelligent routing Discovery Center Mission for the app routing part of the mix. Also recommend a look at the hub-spoke topology mentioned in this earlier post.

Thoughts on production readiness


SAP Private Link is generally available and therefore completely ready for prime time (quoting gowrisankar.m2 from the SAP engineering team 😊).

Cosmos DB powers critical globally available solutions like NEXT GAMES apps with real-time leader board requirements or the data hub of Deutsche Börse AG for instance. For additional stories, have a look at the official portal or the nice community offering Azure Charts.

Cosmos DB scales on its own, match that setup for your CF app on BTP where required with the Application Autoscaler.

Final Words


Aaand cut🎬 Today you saw a multi-region setup with emphasis on private connectivity to the distributed database Azure Cosmos DB from your SAP BTP apps. In addition to that you got a glimpse into a geo-enabled shop-floor use case that requires such a setup and gained some inspiration how to start your own journey.

Looking for more traditional databases like MySQL or Maria DB with SAP CAP enablement? Have a look here.

Any comments regarding your integration journey with SAP Private Link SAP @Developers and @Architects?

The next part of the blog series discusses the serverless scalability aspect of Azure Cosmos DB with SAP Private Link.

Find the related GitHub repos here.

Find your way back to the aggregator blog post here.

As always feel free to ask lots of follow-up questions.

 

Best Regards

Martin
4 Comments
Labels in this area