Menu

Data Limits Rate Limiter

Data Limits rate limiters control the total amount of data (in bytes) that can be transferred during a subscription. They provide a straightforward way to monetize your APIs based on data volume rather than just request count, making them ideal for data-intensive services.

Best Use Case: Data Limits are ideal for content delivery, file storage, data APIs, and other services where the volume of data transferred is a key cost factor.

Types of Data Limits

ApiCharge provides two distinct data limit rate limiters:

Type Description Best For
DataLimitUpload Limits the total amount of data that clients can send to the API File uploads, data ingestion, POST/PUT APIs
DataLimitDownload Limits the total amount of data that clients can receive from the API Content delivery, data export, GET APIs

These can be used independently or together to control both directions of data flow.

How Data Limits Work

Data Limit rate limiters work by:

  1. Starting with a configured maximum byte limit (the Bytes property)
  2. Tracking each byte transferred in the relevant direction
  3. Stopping data transfer once the total byte count is reached

Unlike Stream Rate limiters which control bandwidth (bytes per second), Data Limits control the total cumulative data transfer over the entire duration of the subscription, regardless of how quickly or slowly it is consumed.

Key Features

Data Limit rate limiters provide these essential capabilities:

Data Tracking and Monitoring

ApiCharge accurately tracks data transfer across all supported protocols:

Clients can monitor their data usage through response headers, allowing them to anticipate when they'll need to purchase additional capacity.

Configuration

To configure Data Limit rate limiters in your quote definition, use the following syntax:

{
  "ApiChargeQuotes": {
    "Quotes": [
      {
        "RouteId": "content-api",
        "Duration": 86400,
        "MicroUnitPrice": 500000,
        "RateLimiters": [
          {
            "$type": "DataLimitUpload",
            "Bytes": 10485760
          },
          {
            "$type": "DataLimitDownload",
            "Bytes": 104857600
          }
        ]
      }
    ]
  }
}

In this example:

Byte Size Notation: Use these values as reference:
  • 1 KB = 1,024 bytes
  • 1 MB = 1,048,576 bytes
  • 1 GB = 1,073,741,824 bytes

Tiered Service Example

Creating tiered data services is a common use case for Data Limit rate limiters:

{
  "ApiChargeQuotes": {
    "Quotes": [
      {
        "RouteId": "media-service",
        "Duration": 2592000,
        "MicroUnitPrice": 1000000,
        "RateLimiters": [
          {
            "$type": "DataLimitDownload",
            "Bytes": 1073741824
          }
        ]
      },
      {
        "RouteId": "media-service",
        "Duration": 2592000,
        "MicroUnitPrice": 5000000,
        "RateLimiters": [
          {
            "$type": "DataLimitDownload",
            "Bytes": 5368709120
          }
        ]
      },
      {
        "RouteId": "media-service",
        "Duration": 2592000,
        "MicroUnitPrice": 9000000,
        "RateLimiters": [
          {
            "$type": "DataLimitDownload",
            "Bytes": 10737418240
          }
        ]
      }
    ]
  }
}

This configuration creates three monthly content delivery tiers:

Response When Limit Is Reached

When a client reaches a Data Limit, the behavior depends on the context:

Clients should handle these responses by either waiting for the next subscription period or purchasing a new subscription with a higher data limit.

Performance Considerations

Data Limit rate limiters have minimal performance overhead:

Large File Considerations: For services transferring very large files (>100 MB), consider combining Data Limits with Stream Rate limiters to prevent spikes in memory usage.

Use Cases

Content Delivery

The most common use case is for content delivery services where billing is based on the volume of data transferred:

Data Storage and Processing

For data-focused APIs, data limits can help control both ingestion and retrieval costs:

Combining with Call Count

For comprehensive API monetization, combine Data Limits with Call Count:

{
  "RouteId": "data-api",
  "Duration": 2592000,
  "MicroUnitPrice": 2000000,
  "RateLimiters": [
    {
      "$type": "CallCount",
      "Count": 10000
    },
    {
      "$type": "DataLimitUpload",
      "Bytes": 104857600
    },
    {
      "$type": "DataLimitDownload",
      "Bytes": 1073741824
    }
  ]
}

This configuration limits the API to 10,000 calls, 100 MB of uploads, and 1 GB of downloads, providing protection against various usage patterns that could otherwise lead to unexpected resource consumption.

Next Steps

Now that you understand Data Limit rate limiters, you can explore other rate limiter types: