SlideShare a Scribd company logo
1 of 27
Download to read offline
AdWords API Workshops – All rights reserved
API SERVER

Rate Limits
and API Best Practices

<SPEAKER>, Google, Inc.

AdWords API Workshops – All rights reserved
Agenda
● API Best Practices
● What are Rate Limits?
● How to handle Rate Limits

AdWords API Workshops – All rights reserved
Best Practices
Some simple things to speed up your applications

AdWords API Workshops – All rights reserved
Batch Operations Together

AdWords API Workshops – All rights reserved

● Requests to the API have certain costs
● Network transfer, serialisation, auth, etc.

● Batching operations into a single request reduces these
● mutate methods accept arrays of operations
● MutateJobService for batching

AdWords API Workshops – All rights reserved
Group Operations by Target
● Multiple operations on the same AdGroup / Campaign
are faster
● Subsequent edits to same AdGroup or Campaign can
cause CONCURRENT_MODIFICATION errors
● Backend systems can take time to do their work
● Try to do all edits on AdGroups/Campaigns at once

AdWords API Workshops – All rights reserved
Only Update What you Need to
● Updating an object?
● Only send the values that will change!
● Sending in all the other values wastes
time
●

The system still validates them, stores to DB, etc.

AdWords API Workshops – All rights reserved
A Couple of Other Ideas …
● Compress your requests / response
with gzip
● Make sure User-Agent: has “gzip”
● Accept-Encoding: lists gzip

● Use partial failure feature
● Tells API to serialise those ops that
succeeded
● Returns list of those that failed
AdWords API Workshops – All rights reserved
Defining Rate Limits

AdWords API Workshops – All rights reserved
Rate Limits
● Are not fixed
● Vary on server load
● Vary per feature area
● Will change over time
● Different per AdWords service

AdWords API Workshops – All rights reserved

Defining Rate Limits
Rate Limit Errors
● RATE_EXCEEDED
○ at least wait retryAfterSeconds seconds

● CONCURRENT_MODIFICATIONS
○ Exponential backoff, few retries only

● UNEXPECTED_INTERNAL_API_ERROR
○ Exponential back off, few retries only
○ Report the issue to your CSR or forum
AdWords API Workshops – All rights reserved

Defining Rate Limits
How to Handle Rate Limits
Careful coding...

AdWords API Workshops – All rights reserved
Basic Example
Java

ApiError[] errorArray = apiException.getErrors();
for (ApiError apiError : errorArray) {
if (apiError instanceof RateExceededError) {
int seconds = ((RateExceededError) apiError)
.getRetryAfterSeconds();
// wait the amount of seconds the server asked
Thread.sleep(seconds * 1000);
}
}
AdWords API Workshops – All rights reserved

How to handle Rate Limits
Basic Example - Explained
● Any request can generate a RateExceededError
● Handling these errors is very important
● Wait and retry is the best strategy in
this case
● Even more important when
doing multiple requests

AdWords API Workshops – All rights reserved
Important Points About the Basic Solution
● Synchronous solution to the problem
● Blocks the thread until it succeeds, or fails completely
● No control over request rate speed
● Very difficult to group operations

AdWords API Workshops – All rights reserved
A More Advanced Solution
● Message Queues
● The perfect solution to distribute load and do
throttling
● Very good out of the box solutions available
●

ActiveMQ, RabbitMQ, … etc.

● A lot of tools / client libraries to handle
comms layer

AdWords API Workshops – All rights reserved
Message Queues (cont’d)
● More control over the rates and limits
● Better break down into specialized modules
● Let’s take a look to three possible approaches to the
problem...

AdWords API Workshops – All rights reserved
1. Single Queue
Producer

Producers will create tasks to be
executed using the API, and add
them to the queue

Producer

Consumers
Consumers
Consumers

X

Queue

Throttling

Producer

Logging

Error

Consumers will retrieve the messages/tasks
from the queue with a controlled rate limit
AdWords API Workshops – All rights reserved

How to handle Rate Limits
First Approach - Pros & Cons
● Pros:
● Very easy to implement
● Only one control point to change rate speed
● Easy to handle errors

● Cons:
●
●
●
●

Only one control point to change rate speed
Hard to group operations
Tasks can take too long to be executed
Not all MQs deal with message priority

AdWords API Workshops – All rights reserved
2. Single Queue with Selectors
Producers
Producers

Producers will create specific tasks
to be executed, and add them to
the queue with a specific header

Producers
Producers

Each specific consumer can group
the operations, and execute within
your own rate limit using selectors
X
X
X
X

Producers
Producers

Queue

Throttling

Producers
Producers

Producers
Consumer

AdWords API Workshops – All rights reserved

Producers
Consumer
Producers
Consumer
Producers
Consumer

Error

How to handle Rate Limits
Second Approach - Pros & Cons
● Pros:
● Group operations by type
● Some control over throttling depending on type
● More efficient - better parallel access to the API

● Cons:
●
●
●
●

Only one queue - difficult to administer
No main control on how fast the API is called
Managing all the pieces can be difficult
Operation logging might be complicated

AdWords API Workshops – All rights reserved
3. Multiple Queues
Executors do the request

Producers
Consumer

Producers
Producers

Producers
Consumer

Throttling

Producers
Producers

Producers
Producers
Producers
Producers

Producers
Consumer
Producers
Executors
Executors
Executors

Producers
Consumer
Queues

Consumers just group the tasks
Error

Logging

X
X
X
X

Producers just spawn
a lot of tasks

Throttling

AdWords API Workshops – All rights reserved

How to handle Rate Limits
Third Approach - Pros & Cons
● Pros:
●
●
●
●
●
●

Total control over rate limits
Very robust - very easy to add new parts
Complete picture on what is happening with the queues
Easy to scale based on demand
If done properly, easy to do maintenance!
Super efficient - Parallel grouping; Parallel access to the API

● Cons:
● Hard to implement properly - experience required

AdWords API Workshops – All rights reserved
Message Queues - Takeaways
● Complexity of your platform dictates the best solution
● You can combine parts of other solutions!
● It is a complex subject, but will save you in the long run
● Invest a lot in monitoring. A lot!
● There is no silver bullet...

AdWords API Workshops – All rights reserved
Resources
API Best Practices - https://developers.google.
com/adwords/api/docs/guides/bestpractices
ActiveMQ - http://activemq.apache.org/
RabbitMQ - http://www.rabbitmq.com/
AdWords API Workshops – All rights reserved
Questions?
Thank you!

AdWords API Workshops – All rights reserved
AdWords API Workshops – All rights reserved

More Related Content

What's hot

What's hot (9)

Hp bpt
Hp bptHp bpt
Hp bpt
 
A/B testing platform on Elixir
A/B testing platform on Elixir A/B testing platform on Elixir
A/B testing platform on Elixir
 
Episode 19 - Asynchronous Apex - Batch apex & schedulers
Episode 19 - Asynchronous Apex - Batch apex & schedulersEpisode 19 - Asynchronous Apex - Batch apex & schedulers
Episode 19 - Asynchronous Apex - Batch apex & schedulers
 
2º Encontro GUG Rio de Janeiro/2010
2º Encontro GUG Rio de Janeiro/20102º Encontro GUG Rio de Janeiro/2010
2º Encontro GUG Rio de Janeiro/2010
 
The A, B, Cs of What to Expect
The A, B, Cs of What to ExpectThe A, B, Cs of What to Expect
The A, B, Cs of What to Expect
 
Gcp cloud certification training course
Gcp cloud certification training courseGcp cloud certification training course
Gcp cloud certification training course
 
Q-Plan
Q-PlanQ-Plan
Q-Plan
 
Tesla final presentation ent
Tesla final presentation entTesla final presentation ent
Tesla final presentation ent
 
Episode 9 - Building soap integrations in salesforce
Episode 9 - Building soap integrations  in salesforceEpisode 9 - Building soap integrations  in salesforce
Episode 9 - Building soap integrations in salesforce
 

Similar to Rate limits and performance Talk

AdWords API - How to build a platform
AdWords API - How to build a platformAdWords API - How to build a platform
AdWords API - How to build a platform
TimoBoz
 
How_to_create_modular_microservice_test_projects.pdf
How_to_create_modular_microservice_test_projects.pdfHow_to_create_modular_microservice_test_projects.pdf
How_to_create_modular_microservice_test_projects.pdf
skimorod
 
WSO2Con Asia 2014 - Effective Test Automation in an Agile Environment
WSO2Con Asia 2014 - Effective Test Automation in an Agile EnvironmentWSO2Con Asia 2014 - Effective Test Automation in an Agile Environment
WSO2Con Asia 2014 - Effective Test Automation in an Agile Environment
WSO2
 

Similar to Rate limits and performance Talk (20)

AdWords API - How to build a platform
AdWords API - How to build a platformAdWords API - How to build a platform
AdWords API - How to build a platform
 
How_to_create_modular_microservice_test_projects.pdf
How_to_create_modular_microservice_test_projects.pdfHow_to_create_modular_microservice_test_projects.pdf
How_to_create_modular_microservice_test_projects.pdf
 
API Update Rundown
API Update RundownAPI Update Rundown
API Update Rundown
 
AwReporting Tool
AwReporting ToolAwReporting Tool
AwReporting Tool
 
Client-Side Performance Testing
Client-Side Performance TestingClient-Side Performance Testing
Client-Side Performance Testing
 
Why use ad words api
Why use ad words apiWhy use ad words api
Why use ad words api
 
Reporting tips & tricks
Reporting tips & tricksReporting tips & tricks
Reporting tips & tricks
 
Nginx Conference 2016 - Learnings and State of the Industry
Nginx Conference 2016 - Learnings and State of the IndustryNginx Conference 2016 - Learnings and State of the Industry
Nginx Conference 2016 - Learnings and State of the Industry
 
QTP Automation Testing Tutorial 1
QTP Automation Testing Tutorial 1QTP Automation Testing Tutorial 1
QTP Automation Testing Tutorial 1
 
A differnt Type of Supermarket Delivery
A differnt Type of Supermarket DeliveryA differnt Type of Supermarket Delivery
A differnt Type of Supermarket Delivery
 
Performance testing with JMeter
Performance testing with JMeterPerformance testing with JMeter
Performance testing with JMeter
 
Test Automation for QTP
Test Automation for QTPTest Automation for QTP
Test Automation for QTP
 
Test Automation
Test AutomationTest Automation
Test Automation
 
Api gateway : To be or not to be
Api gateway : To be or not to beApi gateway : To be or not to be
Api gateway : To be or not to be
 
Designing Fault Tolerant APIs to keep Application Network Intact | MuleSoft M...
Designing Fault Tolerant APIs to keep Application Network Intact | MuleSoft M...Designing Fault Tolerant APIs to keep Application Network Intact | MuleSoft M...
Designing Fault Tolerant APIs to keep Application Network Intact | MuleSoft M...
 
AdWords Scripts
AdWords ScriptsAdWords Scripts
AdWords Scripts
 
Reporting tips & tricks
Reporting tips & tricks  Reporting tips & tricks
Reporting tips & tricks
 
WSO2Con Asia 2014 - Effective Test Automation in an Agile Environment
WSO2Con Asia 2014 - Effective Test Automation in an Agile EnvironmentWSO2Con Asia 2014 - Effective Test Automation in an Agile Environment
WSO2Con Asia 2014 - Effective Test Automation in an Agile Environment
 
Training Webinar: Detect Performance Bottlenecks of Applications
Training Webinar: Detect Performance Bottlenecks of ApplicationsTraining Webinar: Detect Performance Bottlenecks of Applications
Training Webinar: Detect Performance Bottlenecks of Applications
 
AdWords API Feed Services
AdWords API Feed ServicesAdWords API Feed Services
AdWords API Feed Services
 

More from marcwan

Getting started with Google Analytics and the AdWords API
Getting started with Google Analytics and the AdWords APIGetting started with Google Analytics and the AdWords API
Getting started with Google Analytics and the AdWords API
marcwan
 
Bid Estimation with the AdWords API (v2)
Bid Estimation with the AdWords API (v2)Bid Estimation with the AdWords API (v2)
Bid Estimation with the AdWords API (v2)
marcwan
 
Opportunity Analysis with Kratu (v2)
Opportunity Analysis with Kratu (v2)Opportunity Analysis with Kratu (v2)
Opportunity Analysis with Kratu (v2)
marcwan
 
Opportunity Analysis with Kratu
Opportunity Analysis with KratuOpportunity Analysis with Kratu
Opportunity Analysis with Kratu
marcwan
 
07. feeds update
07. feeds update07. feeds update
07. feeds update
marcwan
 
AdWords API & OAuth 2.0, Advanced
AdWords API & OAuth 2.0, Advanced AdWords API & OAuth 2.0, Advanced
AdWords API & OAuth 2.0, Advanced
marcwan
 
AdWords Scripts and MCC Scripting
AdWords Scripts and MCC ScriptingAdWords Scripts and MCC Scripting
AdWords Scripts and MCC Scripting
marcwan
 
AwReporting Update
AwReporting UpdateAwReporting Update
AwReporting Update
marcwan
 
Getting Started with AdWords API and Google Analytics
Getting Started with AdWords API and Google AnalyticsGetting Started with AdWords API and Google Analytics
Getting Started with AdWords API and Google Analytics
marcwan
 
Shopping Campaigns and AdWords API
Shopping Campaigns and AdWords APIShopping Campaigns and AdWords API
Shopping Campaigns and AdWords API
marcwan
 
API Updates for v201402
API Updates for v201402API Updates for v201402
API Updates for v201402
marcwan
 
AdWords API Targeting Options
AdWords API Targeting OptionsAdWords API Targeting Options
AdWords API Targeting Options
marcwan
 

More from marcwan (20)

Mcc scripts deck (日本語)
Mcc scripts deck (日本語)Mcc scripts deck (日本語)
Mcc scripts deck (日本語)
 
Getting started with Google Analytics and the AdWords API
Getting started with Google Analytics and the AdWords APIGetting started with Google Analytics and the AdWords API
Getting started with Google Analytics and the AdWords API
 
Bid Estimation with the AdWords API (v2)
Bid Estimation with the AdWords API (v2)Bid Estimation with the AdWords API (v2)
Bid Estimation with the AdWords API (v2)
 
Opportunity Analysis with Kratu (v2)
Opportunity Analysis with Kratu (v2)Opportunity Analysis with Kratu (v2)
Opportunity Analysis with Kratu (v2)
 
Opportunity Analysis with Kratu
Opportunity Analysis with KratuOpportunity Analysis with Kratu
Opportunity Analysis with Kratu
 
07. feeds update
07. feeds update07. feeds update
07. feeds update
 
AdWords API & OAuth 2.0, Advanced
AdWords API & OAuth 2.0, Advanced AdWords API & OAuth 2.0, Advanced
AdWords API & OAuth 2.0, Advanced
 
AdWords Scripts and MCC Scripting
AdWords Scripts and MCC ScriptingAdWords Scripts and MCC Scripting
AdWords Scripts and MCC Scripting
 
AwReporting Update
AwReporting UpdateAwReporting Update
AwReporting Update
 
Getting Started with AdWords API and Google Analytics
Getting Started with AdWords API and Google AnalyticsGetting Started with AdWords API and Google Analytics
Getting Started with AdWords API and Google Analytics
 
Shopping Campaigns and AdWords API
Shopping Campaigns and AdWords APIShopping Campaigns and AdWords API
Shopping Campaigns and AdWords API
 
API Updates for v201402
API Updates for v201402API Updates for v201402
API Updates for v201402
 
AdWords API Targeting Options
AdWords API Targeting OptionsAdWords API Targeting Options
AdWords API Targeting Options
 
Reporting Tips and Tricks (Spanish)
Reporting Tips and Tricks (Spanish)Reporting Tips and Tricks (Spanish)
Reporting Tips and Tricks (Spanish)
 
Rate limits and performance (Spanish)
Rate limits and performance (Spanish)Rate limits and performance (Spanish)
Rate limits and performance (Spanish)
 
OAuth 2.0 (Spanish)
OAuth 2.0 (Spanish)OAuth 2.0 (Spanish)
OAuth 2.0 (Spanish)
 
End to-end how to build a platform (Spanish)
End to-end how to build a platform (Spanish)End to-end how to build a platform (Spanish)
End to-end how to build a platform (Spanish)
 
AwReporting tool introduction (Spanish)
AwReporting tool introduction (Spanish)AwReporting tool introduction (Spanish)
AwReporting tool introduction (Spanish)
 
Api update rundown (Spanish)
Api update rundown (Spanish)Api update rundown (Spanish)
Api update rundown (Spanish)
 
AdWords Scripts (Spanish)
AdWords Scripts (Spanish)AdWords Scripts (Spanish)
AdWords Scripts (Spanish)
 

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Recently uploaded (20)

DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 

Rate limits and performance Talk

  • 1. AdWords API Workshops – All rights reserved
  • 2. API SERVER Rate Limits and API Best Practices <SPEAKER>, Google, Inc. AdWords API Workshops – All rights reserved
  • 3. Agenda ● API Best Practices ● What are Rate Limits? ● How to handle Rate Limits AdWords API Workshops – All rights reserved
  • 4. Best Practices Some simple things to speed up your applications AdWords API Workshops – All rights reserved
  • 5. Batch Operations Together AdWords API Workshops – All rights reserved ● Requests to the API have certain costs ● Network transfer, serialisation, auth, etc. ● Batching operations into a single request reduces these ● mutate methods accept arrays of operations ● MutateJobService for batching AdWords API Workshops – All rights reserved
  • 6. Group Operations by Target ● Multiple operations on the same AdGroup / Campaign are faster ● Subsequent edits to same AdGroup or Campaign can cause CONCURRENT_MODIFICATION errors ● Backend systems can take time to do their work ● Try to do all edits on AdGroups/Campaigns at once AdWords API Workshops – All rights reserved
  • 7. Only Update What you Need to ● Updating an object? ● Only send the values that will change! ● Sending in all the other values wastes time ● The system still validates them, stores to DB, etc. AdWords API Workshops – All rights reserved
  • 8. A Couple of Other Ideas … ● Compress your requests / response with gzip ● Make sure User-Agent: has “gzip” ● Accept-Encoding: lists gzip ● Use partial failure feature ● Tells API to serialise those ops that succeeded ● Returns list of those that failed AdWords API Workshops – All rights reserved
  • 9. Defining Rate Limits AdWords API Workshops – All rights reserved
  • 10. Rate Limits ● Are not fixed ● Vary on server load ● Vary per feature area ● Will change over time ● Different per AdWords service AdWords API Workshops – All rights reserved Defining Rate Limits
  • 11. Rate Limit Errors ● RATE_EXCEEDED ○ at least wait retryAfterSeconds seconds ● CONCURRENT_MODIFICATIONS ○ Exponential backoff, few retries only ● UNEXPECTED_INTERNAL_API_ERROR ○ Exponential back off, few retries only ○ Report the issue to your CSR or forum AdWords API Workshops – All rights reserved Defining Rate Limits
  • 12. How to Handle Rate Limits Careful coding... AdWords API Workshops – All rights reserved
  • 13. Basic Example Java ApiError[] errorArray = apiException.getErrors(); for (ApiError apiError : errorArray) { if (apiError instanceof RateExceededError) { int seconds = ((RateExceededError) apiError) .getRetryAfterSeconds(); // wait the amount of seconds the server asked Thread.sleep(seconds * 1000); } } AdWords API Workshops – All rights reserved How to handle Rate Limits
  • 14. Basic Example - Explained ● Any request can generate a RateExceededError ● Handling these errors is very important ● Wait and retry is the best strategy in this case ● Even more important when doing multiple requests AdWords API Workshops – All rights reserved
  • 15. Important Points About the Basic Solution ● Synchronous solution to the problem ● Blocks the thread until it succeeds, or fails completely ● No control over request rate speed ● Very difficult to group operations AdWords API Workshops – All rights reserved
  • 16. A More Advanced Solution ● Message Queues ● The perfect solution to distribute load and do throttling ● Very good out of the box solutions available ● ActiveMQ, RabbitMQ, … etc. ● A lot of tools / client libraries to handle comms layer AdWords API Workshops – All rights reserved
  • 17. Message Queues (cont’d) ● More control over the rates and limits ● Better break down into specialized modules ● Let’s take a look to three possible approaches to the problem... AdWords API Workshops – All rights reserved
  • 18. 1. Single Queue Producer Producers will create tasks to be executed using the API, and add them to the queue Producer Consumers Consumers Consumers X Queue Throttling Producer Logging Error Consumers will retrieve the messages/tasks from the queue with a controlled rate limit AdWords API Workshops – All rights reserved How to handle Rate Limits
  • 19. First Approach - Pros & Cons ● Pros: ● Very easy to implement ● Only one control point to change rate speed ● Easy to handle errors ● Cons: ● ● ● ● Only one control point to change rate speed Hard to group operations Tasks can take too long to be executed Not all MQs deal with message priority AdWords API Workshops – All rights reserved
  • 20. 2. Single Queue with Selectors Producers Producers Producers will create specific tasks to be executed, and add them to the queue with a specific header Producers Producers Each specific consumer can group the operations, and execute within your own rate limit using selectors X X X X Producers Producers Queue Throttling Producers Producers Producers Consumer AdWords API Workshops – All rights reserved Producers Consumer Producers Consumer Producers Consumer Error How to handle Rate Limits
  • 21. Second Approach - Pros & Cons ● Pros: ● Group operations by type ● Some control over throttling depending on type ● More efficient - better parallel access to the API ● Cons: ● ● ● ● Only one queue - difficult to administer No main control on how fast the API is called Managing all the pieces can be difficult Operation logging might be complicated AdWords API Workshops – All rights reserved
  • 22. 3. Multiple Queues Executors do the request Producers Consumer Producers Producers Producers Consumer Throttling Producers Producers Producers Producers Producers Producers Producers Consumer Producers Executors Executors Executors Producers Consumer Queues Consumers just group the tasks Error Logging X X X X Producers just spawn a lot of tasks Throttling AdWords API Workshops – All rights reserved How to handle Rate Limits
  • 23. Third Approach - Pros & Cons ● Pros: ● ● ● ● ● ● Total control over rate limits Very robust - very easy to add new parts Complete picture on what is happening with the queues Easy to scale based on demand If done properly, easy to do maintenance! Super efficient - Parallel grouping; Parallel access to the API ● Cons: ● Hard to implement properly - experience required AdWords API Workshops – All rights reserved
  • 24. Message Queues - Takeaways ● Complexity of your platform dictates the best solution ● You can combine parts of other solutions! ● It is a complex subject, but will save you in the long run ● Invest a lot in monitoring. A lot! ● There is no silver bullet... AdWords API Workshops – All rights reserved
  • 25. Resources API Best Practices - https://developers.google. com/adwords/api/docs/guides/bestpractices ActiveMQ - http://activemq.apache.org/ RabbitMQ - http://www.rabbitmq.com/ AdWords API Workshops – All rights reserved
  • 26. Questions? Thank you! AdWords API Workshops – All rights reserved
  • 27. AdWords API Workshops – All rights reserved