I want to apply the CDN but I need to control the usage of each request, how I could achieve this?

Eduard Tomàs 25 Reputation points
2023-09-25T12:57:27.3633333+00:00

Hi everyone I would like help on knowing how to do a particular thing with de Azure CDN. My use case is I need to implement a CDN on a service that we have, that retrieve files basically. The key is that we control the usage of our users (downloading size for each request) and this usage it's control on our end-host service. So I want to apply the CDN but I need to control the usage of each request, how I could achieve this? And what's the best way to do it?

Azure Content Delivery Network
{count} votes

Accepted answer
  1. GitaraniSharma-MSFT 49,256 Reputation points Microsoft Employee
    2023-10-05T11:52:01.63+00:00

    Hello @Eduard Tomàs ,

    I understand that you've a backend application which keep tracks of every request to get information and then extract data to bill your client and all this logic is implemented on your end. You also have a Microsoft classic CDN with caching enabled in front of your backend application and when the CDN gets a HIT, the content is served from the CDN edge cache and the request doesn't reach the backend, so you are not able to collect the required data. And hence you are getting the data from log analytics by running queries. But you would like to know if there is any other way to implement this setup, so that your backend gets the data even when CDN is HIT.

    I don't think it is possible to configure the CDN in a way that your backend gets the data even when CDN is HIT.

    When CDN is hit, the content is served from the cache and the request doesn't go to the backend.

    And since you want to use CDN caching but also want to get the billing data, the only thing that I could think of is to use the CDN raw logs.

    Azure CDN from Microsoft Service currently provides Raw logs, and it is called AzureCdnAccessLog.

    As mentioned in the Azure CDN monitoring document,

    Raw logs include logs generated from both CDN edge (child POP) and origin shield. Origin shield refers to parent nodes that are strategically located across the globe. These nodes communicate with origin servers and reduce the traffic load on origin.

    For every request that goes to origin shield, there are two log entries:

    • One for edge nodes.
    • One for origin shield.

    To differentiate the egress or responses from the edge nodes vs. origin shield, you can use the field isReceivedFromClient to get the correct data.

    If the value is false, then it means the request is responded from origin shield to edge nodes. This approach is effective to compare raw logs with billing data. Charges aren't incurred for egress from origin shield to the edge nodes. Charges are incurred for egress from the edge nodes to clients.

    You can use the below Kusto query sample to exclude logs generated on origin shield in Log Analytics.

    AzureDiagnostics 
    | where OperationName == "Microsoft.Cdn/Profiles/AccessLog/Write" and Category == "AzureCdnAccessLog"  
    | where isReceivedFromClient == true
    

    You confirmed that Azure CDN raw logs helped you achieve your requirement, and the issue is now resolved.

    Kindly let us know if you need further assistance on this issue.


    Please don’t forget to close the thread by clicking "Accept the answer", as this can be beneficial to other community members.

    0 comments No comments

0 additional answers

Sort by: Most helpful