Using data as service - limit the amount of data being pulled out of backend server per day

Not applicable

We have API Gateway 4.17.09, installed on private cloud with CentOS 7.4.

We have a requirement to support data-as-a-service.

Essentially, we need to be able to limit the amount of data being pulled out of backend server per day.

Is there is a way to do it, in API Gateway?

Solved Solved
0 4 155
1 ACCEPTED SOLUTION

Yes, you could do it.

You would need to employ a quota policy.

  • set the quota to be of type calendar, and set to reset at 12:00 midnight each day, or whatever time of day is appropriate for your data-as-a-service.
  • set the quota limit to X number of bytes, whatever is allowed by the service.
  • set the identifier to be a fixed string, corresponding to the data-as-a-service. This can be anything.
  • apply the quota on proxy request. it will reject calls if the quota has tripped. In this case, you can have the proxy return a 429 or other appropriate code, and any message you like using FaultRules.
    <Quota name="Quota-OnRequest" type="calendar">
        <StartTime>2018-03-20 00:00:00</StartTime>
        <Interval>1</Interval>
        <TimeUnit>day</TimeUnit>
        <Allow count="10737418240"/>
        <Synchronous>false</Synchronous>
        <Distributed>true</Distributed>
        <Identifier>My-Data-As-A-Service</Identifier>
    </Quota>
    	
  • also apply the quota on the response. We don't want the quota to reject calls here, but we want it to add to the "used count", so use continueOnError='true'. Use MessageWeight here as the size in bytes of the received response.
    <Quota name="Quota-OnResponse" continueOnError='true' type="calendar">
        <StartTime>2018-03-20 00:00:00</StartTime>
        <Interval>1</Interval>
        <TimeUnit>day</TimeUnit>
        <Allow count="10737418240"/>
        <Synchronous>false</Synchronous>
        <Distributed>true</Distributed>
        <Identifier>My-Data-As-A-Service</Identifier>
        <MessageWeight ref="size_in_bytes_of_response"/>
    </Quota>
    	

You could combine this with caching to reduce the load on the data-as-a-service, too.

View solution in original post

4 REPLIES 4

Yes, you could do it.

You would need to employ a quota policy.

  • set the quota to be of type calendar, and set to reset at 12:00 midnight each day, or whatever time of day is appropriate for your data-as-a-service.
  • set the quota limit to X number of bytes, whatever is allowed by the service.
  • set the identifier to be a fixed string, corresponding to the data-as-a-service. This can be anything.
  • apply the quota on proxy request. it will reject calls if the quota has tripped. In this case, you can have the proxy return a 429 or other appropriate code, and any message you like using FaultRules.
    <Quota name="Quota-OnRequest" type="calendar">
        <StartTime>2018-03-20 00:00:00</StartTime>
        <Interval>1</Interval>
        <TimeUnit>day</TimeUnit>
        <Allow count="10737418240"/>
        <Synchronous>false</Synchronous>
        <Distributed>true</Distributed>
        <Identifier>My-Data-As-A-Service</Identifier>
    </Quota>
    	
  • also apply the quota on the response. We don't want the quota to reject calls here, but we want it to add to the "used count", so use continueOnError='true'. Use MessageWeight here as the size in bytes of the received response.
    <Quota name="Quota-OnResponse" continueOnError='true' type="calendar">
        <StartTime>2018-03-20 00:00:00</StartTime>
        <Interval>1</Interval>
        <TimeUnit>day</TimeUnit>
        <Allow count="10737418240"/>
        <Synchronous>false</Synchronous>
        <Distributed>true</Distributed>
        <Identifier>My-Data-As-A-Service</Identifier>
        <MessageWeight ref="size_in_bytes_of_response"/>
    </Quota>
    	

You could combine this with caching to reduce the load on the data-as-a-service, too.

<MessageWeightref="size_in_bytes_of_response"/> The purpose of this statement is not clear. Moreover from where will be the value of size_in_bytes_of_response be fetched? 

Hi, if you have a new question, ask a new question. Don't post new questions as comments to answers for old questions.

7166-ask-a-question.png

This code actually counts the no of hits not the amount of the data being pulled from server