SlideShare a Scribd company logo
1 of 22
Download to read offline
Victor Quinn
@victorquinn
Lead Node.js Engineer
Designing an API for Mobile
API Craft DMV Meetup, April 28 2014
Download
Gives you real-time information
on the people around you
!
It’s free!!
!
This will be pretty fast-paced
More About SocialRadar
Special considerations for a
Mobile API
• Speed really matters
• Battery usage - minimize
• Maximizing network utilization
• Response size matters
• Minimize number of requests
• Stateless
Speed: Problems
• Only one thing on screen at a time, perception change
• On desktop other things can distract
• Best Case: ~400ms latency for round trip on cell network
• We tested at SocialRadar using a basic ping no-op
endpoint
• Verizon LTE, iPhone 5S
• Device doesn’t maintain active connection
• Average case much worse, ~1000ms round trip
Ideal round trip
iPhone 5S on Verizon LTE
User's Phone API
200ms
200ms
200ms
Total round trip time 800ms
200ms
bit of hand waving, I’m not
a network expert
Likely round trip
iPhone 4S on Verizon 3G
User's Phone API
500ms
500ms
200ms
Total round trip time 1600ms
400ms
Speed: Solutions
• Cache anything humanly possible
• Respond as quickly as possible, deferring
anything that doesn’t need to be done immediately
• Queue most things
• Make sure your API can handle high concurrency
(we settled on Node.js to accomplish this,
WhatsApp uses Erlang)
Minimize battery usage
!
• Brief note about cell battery and network
usage (more)
• Response size matters
• Minimize number of requests
Maximize network utilization
Response Size: Problems
• At SocialRadar, we tested responses of different sizes
• Optimal was largest response that would fit into a
single TCP packet on the cell network.
• Around 128KB. Differs based on client device and
network
• Any longer would jump response time significantly
Response Size: Solutions
• Paging sizes — largest
that fit within TCP packet
window
• Contrast with
Desktop, paging more
dependent on server
response time and UI
User's Phone API
200ms
200ms
200ms
Total round trip time 800ms
200ms
Page size of 20 users
To retrieve 100 users, ~4s
Paging Size: 20 (Ideal)
Paging Size: 50 (Ideal)
User's Phone API
200ms
200ms
500ms
Total round trip time 1100ms
200ms
Page size of 50 users
To retrieve 100 users, ~2.2s
Paging Size: 20 (Likely)
User's Phone API
500ms
500ms
200ms
Total round trip time 1600ms
400ms
To retrieve 100 users, ~8s
Paging Size: 50 (Likely)
User's Phone API
500ms
500ms
500ms
Total round trip time 1900ms
400ms
To retrieve 100 users, ~3.8s
Number of Requests: Problems
• Traditionally parallelized, not (well) on mobile
• Battery life is of great concern and every network
request eats into that
• Spinning up the cell modem, making request,
waiting for it drains the battery
• So if you make 5 requests instead of 1, draining
battery, leaving user waiting
Number of Requests: Solutions
• Paging size as mentioned above, try to maximize
response that will fit in a packet to minimize the
number of requests
• So one request with 20KB much better than 5
with 4KB each
• Batch multiple requests into a single one
Batch Request Library
• Finding no great existing batch request library for
Node.js, we rolled our own open source library
• http://batch-request.socialradar.com
• Allows you to send a single request that represents
multiple
• No need to compromise on RESTful principles and
move to a SOA
• Handles complex dependencies
Batch Request Library (2)
1. npm install batch-request
2. Add one line of code to your API:

app.post('/batch', batch.validate, batch);!
3. Send batch request as single POST:

{

"myRequest1": {

"method": "GET",

"uri": "http://api.mysite.com/users/1/first_name"

},

"myRequest2": {

"method": "GET",

"uri": "http://api.mysite.com/users/1/email"

}

}
Batch Request Library (3)
4. Receive single response:

{

"myRequest1": {

“statusCode": 200,

“body": “Victor”,

“headers”: {…}

},

"myRequest2": {

“statusCode": 200,

“body": “victor@socialradar.com”,

“headers”: {…}

}

}
When you pull to refresh,
Batch Request to:
• Update user location with
latest GPS reading
• Retrieve current City/State
• Retrieve most recent stat
numbers
• Get some user lists to
cache them
Stateless
• Cell networks are spotty
• For performance, want load balance among
multiple servers
• Solution: Assign access token to device rather than
relying on sessions for user access
• We have an access token which is an encrypted
string containing user_id and some other stuff
Victor Quinn
@victorquinn
Lead Node.js Engineer
!
Download our App
Questions?

More Related Content

Recently uploaded

CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual serviceCALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual serviceanilsa9823
 
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCR
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCRFULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCR
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCRnishacall1
 
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost Lover
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost LoverPowerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost Lover
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost LoverPsychicRuben LoveSpells
 
9892124323 | Book Call Girls in Juhu and escort services 24x7
9892124323 | Book Call Girls in Juhu and escort services 24x79892124323 | Book Call Girls in Juhu and escort services 24x7
9892124323 | Book Call Girls in Juhu and escort services 24x7Pooja Nehwal
 
BDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort ServiceBDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort ServiceDelhi Call girls
 
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun service
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun serviceCALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun service
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun serviceanilsa9823
 
Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,
Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,
Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,Pooja Nehwal
 

Recently uploaded (7)

CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual serviceCALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual service
 
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCR
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCRFULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCR
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCR
 
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost Lover
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost LoverPowerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost Lover
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost Lover
 
9892124323 | Book Call Girls in Juhu and escort services 24x7
9892124323 | Book Call Girls in Juhu and escort services 24x79892124323 | Book Call Girls in Juhu and escort services 24x7
9892124323 | Book Call Girls in Juhu and escort services 24x7
 
BDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort ServiceBDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort Service
 
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun service
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun serviceCALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun service
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun service
 
Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,
Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,
Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,
 

Featured

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 

Featured (20)

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 

Designing an API for Mobile - SocialRadar

  • 1. Victor Quinn @victorquinn Lead Node.js Engineer Designing an API for Mobile API Craft DMV Meetup, April 28 2014
  • 2. Download Gives you real-time information on the people around you ! It’s free!! ! This will be pretty fast-paced More About SocialRadar
  • 3. Special considerations for a Mobile API • Speed really matters • Battery usage - minimize • Maximizing network utilization • Response size matters • Minimize number of requests • Stateless
  • 4. Speed: Problems • Only one thing on screen at a time, perception change • On desktop other things can distract • Best Case: ~400ms latency for round trip on cell network • We tested at SocialRadar using a basic ping no-op endpoint • Verizon LTE, iPhone 5S • Device doesn’t maintain active connection • Average case much worse, ~1000ms round trip
  • 5. Ideal round trip iPhone 5S on Verizon LTE User's Phone API 200ms 200ms 200ms Total round trip time 800ms 200ms bit of hand waving, I’m not a network expert
  • 6. Likely round trip iPhone 4S on Verizon 3G User's Phone API 500ms 500ms 200ms Total round trip time 1600ms 400ms
  • 7. Speed: Solutions • Cache anything humanly possible • Respond as quickly as possible, deferring anything that doesn’t need to be done immediately • Queue most things • Make sure your API can handle high concurrency (we settled on Node.js to accomplish this, WhatsApp uses Erlang)
  • 8. Minimize battery usage ! • Brief note about cell battery and network usage (more) • Response size matters • Minimize number of requests Maximize network utilization
  • 9. Response Size: Problems • At SocialRadar, we tested responses of different sizes • Optimal was largest response that would fit into a single TCP packet on the cell network. • Around 128KB. Differs based on client device and network • Any longer would jump response time significantly
  • 10. Response Size: Solutions • Paging sizes — largest that fit within TCP packet window • Contrast with Desktop, paging more dependent on server response time and UI
  • 11. User's Phone API 200ms 200ms 200ms Total round trip time 800ms 200ms Page size of 20 users To retrieve 100 users, ~4s Paging Size: 20 (Ideal)
  • 12. Paging Size: 50 (Ideal) User's Phone API 200ms 200ms 500ms Total round trip time 1100ms 200ms Page size of 50 users To retrieve 100 users, ~2.2s
  • 13. Paging Size: 20 (Likely) User's Phone API 500ms 500ms 200ms Total round trip time 1600ms 400ms To retrieve 100 users, ~8s
  • 14. Paging Size: 50 (Likely) User's Phone API 500ms 500ms 500ms Total round trip time 1900ms 400ms To retrieve 100 users, ~3.8s
  • 15. Number of Requests: Problems • Traditionally parallelized, not (well) on mobile • Battery life is of great concern and every network request eats into that • Spinning up the cell modem, making request, waiting for it drains the battery • So if you make 5 requests instead of 1, draining battery, leaving user waiting
  • 16. Number of Requests: Solutions • Paging size as mentioned above, try to maximize response that will fit in a packet to minimize the number of requests • So one request with 20KB much better than 5 with 4KB each • Batch multiple requests into a single one
  • 17. Batch Request Library • Finding no great existing batch request library for Node.js, we rolled our own open source library • http://batch-request.socialradar.com • Allows you to send a single request that represents multiple • No need to compromise on RESTful principles and move to a SOA • Handles complex dependencies
  • 18. Batch Request Library (2) 1. npm install batch-request 2. Add one line of code to your API:
 app.post('/batch', batch.validate, batch);! 3. Send batch request as single POST:
 {
 "myRequest1": {
 "method": "GET",
 "uri": "http://api.mysite.com/users/1/first_name"
 },
 "myRequest2": {
 "method": "GET",
 "uri": "http://api.mysite.com/users/1/email"
 }
 }
  • 19. Batch Request Library (3) 4. Receive single response:
 {
 "myRequest1": {
 “statusCode": 200,
 “body": “Victor”,
 “headers”: {…}
 },
 "myRequest2": {
 “statusCode": 200,
 “body": “victor@socialradar.com”,
 “headers”: {…}
 }
 }
  • 20. When you pull to refresh, Batch Request to: • Update user location with latest GPS reading • Retrieve current City/State • Retrieve most recent stat numbers • Get some user lists to cache them
  • 21. Stateless • Cell networks are spotty • For performance, want load balance among multiple servers • Solution: Assign access token to device rather than relying on sessions for user access • We have an access token which is an encrypted string containing user_id and some other stuff
  • 22. Victor Quinn @victorquinn Lead Node.js Engineer ! Download our App Questions?