Rate Limiting

Understand Rate Limiting

The MoPub SDK imposes minimum wait times between consecutive ad requests. If frequent ad requests result in no fill, MoPub rate-limits the number of outgoing requests. When this happens, the MoPub SDK immediately fails any subsequent requests and notifies publishers via ad failure callbacks.

To prevent MoPub from rate-limiting your ad requests, you can optimize your ad requests and add a minimum wait time of 10 seconds between unfilled ad requests.

Example

Here’s an example of imposing wait times before re-requesting interstitial ads on Android, using Java:

On the class or fragment where you handle interstitial lifecycle events (the class or fragment that implements InterstitialAdListener), you request ads using the load() method on your MoPub interstitial view. Each ad request can either result in success and trigger the onInterstitialLoaded callback, or in failure and trigger the onInterstitialFailed callback.

As we explained above, if many consecutive failures are received and the onInterstitialFailed method is frequently called, then the MoPub SDK triggers rate limiting, and immediately fails the requests. This again causes onInterstitialFailed to be called and can create a loop of failing requests.

This is likely to happen if you are immediately re-requesting an ad on fail callback, like this:

@Override
public void onInterstitialFailed(MoPubInterstitial interstitial, MoPubErrorCode errorCode) {
    // Ad load failed. Should re-request.
    moPubInterstitialView.load();
}

Such a practice is very likely to trigger rate limiting. Instead of allowing load() to be called immediately, wait for some time. There are many ways to achieve this.

As an example, on Android with a 10-second delay, you can use Java’s Handler class to call load() using the postDelayed method:

@Override
public void onInterstitialFailed(MoPubInterstitial interstitial, MoPubErrorCode errorCode) {
    // Ad load failed. Should re-request after 10 seconds.
    final Handler handler = new Handler();
    public static final int TEN_SECONDS_MILLIS = 10 * 1000;

    handler.postDelayed(new Runnable() {
      @Override
      public void run() {
        moPubInterstitialView.load();
      }
    }, delay);
}

This approach re-requests an interstitial ad 10 seconds later, and prevents rate limiting from being triggered.

Last updated August 24, 2020

TWITTER, MOPUB, and the Bird logo are trademarks of Twitter, Inc. or its affiliates. All third party logos and trademarks included are the property of their respective owners.

© 2020 MoPub (a division of Twitter, Inc.)