Dynamic sampling is a feature available on enterprise plans which enables large cost reduction by dynamically sampling API traffic with one-click and no code change.
Sampled API calls are not logged to Moesif nor will they count against your billing quota. As long as Moesif sees a portion of API traffic, Moesif will still extrapolate original metrics so your reporting is accurate
You can create sampling rules based on customer demographics and their behavior such as when customers signed up or whether they ran into API errors.
Companies that have a limited budget for analytics, but have high-volume (millions or billions of API calls per day) will benefit the most from the cost reduction.
How sampling works
With sampling Moesif only sees a portion of your API traffic based on behavioral rules you define which can be user behavior, their demographics, or other criteria. Because Moesif doesn’t see all traffic, you can save cost since you can use Moesif on a higher-volume API beyond your plan as sampled API calls do not count against your quota. For example, if your API usually sees 1 billion API calls per month, but you set the global sample rate to 10%, you only need a plan for 100 million events per month. Because Moesif has full knowledge of your sampling rules, the platform is intelligent enough to extrapolate what the true metrics should be. This means you’ll still have accurate reporting regardless of defined sample rates.
How to set sample rates
Moesif supports three levels of sampling:
- User (or company) specific sampling
- Behaviorally driven sampling
- Global sample rate
Sample rates are prioritized in the above order. Meaning a sample rate set for a specific customer takes priority over the sample rate associated with a behavioral cohort that a customer belongs to. Unsurprisingly, the global sample rate has the lowest priority and is by default set to 100% for all customers.
To access dynamic sampling, go to Alerting & Governance within the the top header menu and then select Sampling & Suppression
Behaviorally driven sampling
Behaviorally driven sampling is the most powerful and common way to leverage dynamic sampling. With behaviorally driven sampling, you apply a sample rate to members of a behavioral cohort which can be something like “Companies who made over 1M API Calls last 4 weeks” or “Newly integrated users who made purchase transactions”. You can create both a company rule or a user rule.
To set a sample rate for a cohort of users or companies:
1. Save a behavioral cohort
If you have not created a behavioral cohort (which drives sampling rules, governance rules, among other things), you will need to create one. This can be done by going to the user (or company) look up from the header bar. Add the customer demographics or behavioral filters you want for the cohort. Once done, click the _Create Cohort_button at top left and give it a name.
In this example, we are selecting users who were created in the last 4 months and performed at least 1 API call to either
/purchases in the last year.
2. Set the sample rate for the cohort
Once you have created a cohort, go back to Sampling & Suppression under Alerting & Governance. Click + User Rule or click + Company Rule based on what on what you created in step 1. From here, you will see a list of saved behavioral cohorts. Select one and then set the sample rate.
In this case, 100% means log all API calls, whereas 0% means suppress all data collection.
The global sample rate is used by any user (or company) that doesn’t have its own sample rate nor belongs to any behavioral cohort. To modify the global sample rate, click on “Global Sampling” button
This also brings up a few other options to suppress traffic such as on IP address or known bots and crawlers.
Auditing current sample rates
In the global sampling area, you’re also able to audit which users or companies are actively being sampled. This is helpful when a user or company belongs to multiple behavioral cohorts creating ambiguity in the effective sample rate.
Any user or company id not listed under Current Sample Rates will fallback to the global sample rate, if set.
User (or company) specific sampling
Finally, any user or company can have a defined sample rate from 0% to 100%. By default, all users sample 100% of API traffic (i.e. all traffic). Reducing any customer to 0% effectively suppresses all data collection for that user (A mechanism to enable GDPR/CCPA compliance). A use case of leveraging user level sampling is to set your 10 largest customers to a less than 100% sample rate, will collect 100% of API traffic for all others.
To set the sample rate for an individual user or company, click on Users or Companies in the top header, then look up the user or company of interest. Once you open up their profile view, click the orange button Edit Sample Rate.