SlideShare a Scribd company logo
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

What's hot

SignalR Overview
SignalR OverviewSignalR Overview
SignalR Overview
Michael Sukachev
 
Altitude SF 2017: The power of the network
Altitude SF 2017: The power of the networkAltitude SF 2017: The power of the network
Altitude SF 2017: The power of the network
Fastly
 
Atmosphere 2016 - Andreas Grabner - Metrics Driven-DevOps: Delivering High Qu...
Atmosphere 2016 - Andreas Grabner - Metrics Driven-DevOps: Delivering High Qu...Atmosphere 2016 - Andreas Grabner - Metrics Driven-DevOps: Delivering High Qu...
Atmosphere 2016 - Andreas Grabner - Metrics Driven-DevOps: Delivering High Qu...
PROIDEA
 
ECS19 - Ingo Gegenwarth - Running Exchange in large environment
ECS19 - Ingo Gegenwarth -  Running Exchangein large environmentECS19 - Ingo Gegenwarth -  Running Exchangein large environment
ECS19 - Ingo Gegenwarth - Running Exchange in large environment
European Collaboration Summit
 
Nzpug google appengine
Nzpug google appengineNzpug google appengine
Nzpug google appengine
stuartmitchell
 
Comet / WebSocket Web Applications
Comet / WebSocket Web ApplicationsComet / WebSocket Web Applications
Comet / WebSocket Web Applications
Codemotion
 
Scale your signalR realtime web application
Scale your signalR realtime web applicationScale your signalR realtime web application
Scale your signalR realtime web application
Ran Wahle
 

What's hot (7)

SignalR Overview
SignalR OverviewSignalR Overview
SignalR Overview
 
Altitude SF 2017: The power of the network
Altitude SF 2017: The power of the networkAltitude SF 2017: The power of the network
Altitude SF 2017: The power of the network
 
Atmosphere 2016 - Andreas Grabner - Metrics Driven-DevOps: Delivering High Qu...
Atmosphere 2016 - Andreas Grabner - Metrics Driven-DevOps: Delivering High Qu...Atmosphere 2016 - Andreas Grabner - Metrics Driven-DevOps: Delivering High Qu...
Atmosphere 2016 - Andreas Grabner - Metrics Driven-DevOps: Delivering High Qu...
 
ECS19 - Ingo Gegenwarth - Running Exchange in large environment
ECS19 - Ingo Gegenwarth -  Running Exchangein large environmentECS19 - Ingo Gegenwarth -  Running Exchangein large environment
ECS19 - Ingo Gegenwarth - Running Exchange in large environment
 
Nzpug google appengine
Nzpug google appengineNzpug google appengine
Nzpug google appengine
 
Comet / WebSocket Web Applications
Comet / WebSocket Web ApplicationsComet / WebSocket Web Applications
Comet / WebSocket Web Applications
 
Scale your signalR realtime web application
Scale your signalR realtime web applicationScale your signalR realtime web application
Scale your signalR realtime web application
 

Viewers also liked

Mobile API Design Techniques
Mobile API Design TechniquesMobile API Design Techniques
Mobile API Design Techniques
Trieu Nguyen
 
Jordi Romero Api for-the-mobile-era
Jordi Romero Api for-the-mobile-eraJordi Romero Api for-the-mobile-era
Jordi Romero Api for-the-mobile-era
.toster
 
Develop and Deploy your Mobile API with Rails, Nginx, Unicorn and Capistrano
Develop and Deploy your Mobile API with Rails, Nginx, Unicorn and CapistranoDevelop and Deploy your Mobile API with Rails, Nginx, Unicorn and Capistrano
Develop and Deploy your Mobile API with Rails, Nginx, Unicorn and Capistrano
Errazudin Ishak
 
Pragmatic Git workflow
Pragmatic Git workflowPragmatic Git workflow
Pragmatic Git workflow
Tomek Cejner
 
Creating an Effective Mobile API
Creating an Effective Mobile API Creating an Effective Mobile API
Creating an Effective Mobile API
Nick DeNardis
 
How to build mobile API with Node.js
How to build mobile API with Node.jsHow to build mobile API with Node.js
How to build mobile API with Node.js
Tomek Cejner
 
Data To Go: Mobile API Design (Lightning Talk)
Data To Go: Mobile API Design (Lightning Talk)Data To Go: Mobile API Design (Lightning Talk)
Data To Go: Mobile API Design (Lightning Talk)
Chuck Greb
 
Api mobile first
Api mobile firstApi mobile first
Api mobile first
Chris Saez
 
Mobile Api and Caching
Mobile Api and CachingMobile Api and Caching
Mobile Api and Caching
New Relic
 
Mobile API: Design & Techniques
Mobile API: Design & TechniquesMobile API: Design & Techniques
Mobile API: Design & Techniques
Fred Brunel
 
Data to Go: Mobile API Design
Data to Go: Mobile API DesignData to Go: Mobile API Design
Data to Go: Mobile API Design
Chuck Greb
 
Data to Go: Mobile API Design (SXSW)
Data to Go: Mobile API Design (SXSW)Data to Go: Mobile API Design (SXSW)
Data to Go: Mobile API Design (SXSW)
Chuck Greb
 
Build a REST API for your Mobile Apps using Node.js
Build a REST API for your Mobile Apps using Node.jsBuild a REST API for your Mobile Apps using Node.js
Build a REST API for your Mobile Apps using Node.js
Stormpath
 
We we should be Mobile API - First, by Brad Hipps
We we should be Mobile API - First, by Brad HippsWe we should be Mobile API - First, by Brad Hipps
We we should be Mobile API - First, by Brad Hipps
Puerto Rico Tech Summit
 
Designing API for mobile apps (MobileWarsaw 19.01.2015)
Designing API for mobile apps (MobileWarsaw 19.01.2015)Designing API for mobile apps (MobileWarsaw 19.01.2015)
Designing API for mobile apps (MobileWarsaw 19.01.2015)
Wojtek Erbetowski
 
Build Features, Not Apps
Build Features, Not AppsBuild Features, Not Apps
Build Features, Not Apps
Natasha Murashev
 

Viewers also liked (16)

Mobile API Design Techniques
Mobile API Design TechniquesMobile API Design Techniques
Mobile API Design Techniques
 
Jordi Romero Api for-the-mobile-era
Jordi Romero Api for-the-mobile-eraJordi Romero Api for-the-mobile-era
Jordi Romero Api for-the-mobile-era
 
Develop and Deploy your Mobile API with Rails, Nginx, Unicorn and Capistrano
Develop and Deploy your Mobile API with Rails, Nginx, Unicorn and CapistranoDevelop and Deploy your Mobile API with Rails, Nginx, Unicorn and Capistrano
Develop and Deploy your Mobile API with Rails, Nginx, Unicorn and Capistrano
 
Pragmatic Git workflow
Pragmatic Git workflowPragmatic Git workflow
Pragmatic Git workflow
 
Creating an Effective Mobile API
Creating an Effective Mobile API Creating an Effective Mobile API
Creating an Effective Mobile API
 
How to build mobile API with Node.js
How to build mobile API with Node.jsHow to build mobile API with Node.js
How to build mobile API with Node.js
 
Data To Go: Mobile API Design (Lightning Talk)
Data To Go: Mobile API Design (Lightning Talk)Data To Go: Mobile API Design (Lightning Talk)
Data To Go: Mobile API Design (Lightning Talk)
 
Api mobile first
Api mobile firstApi mobile first
Api mobile first
 
Mobile Api and Caching
Mobile Api and CachingMobile Api and Caching
Mobile Api and Caching
 
Mobile API: Design & Techniques
Mobile API: Design & TechniquesMobile API: Design & Techniques
Mobile API: Design & Techniques
 
Data to Go: Mobile API Design
Data to Go: Mobile API DesignData to Go: Mobile API Design
Data to Go: Mobile API Design
 
Data to Go: Mobile API Design (SXSW)
Data to Go: Mobile API Design (SXSW)Data to Go: Mobile API Design (SXSW)
Data to Go: Mobile API Design (SXSW)
 
Build a REST API for your Mobile Apps using Node.js
Build a REST API for your Mobile Apps using Node.jsBuild a REST API for your Mobile Apps using Node.js
Build a REST API for your Mobile Apps using Node.js
 
We we should be Mobile API - First, by Brad Hipps
We we should be Mobile API - First, by Brad HippsWe we should be Mobile API - First, by Brad Hipps
We we should be Mobile API - First, by Brad Hipps
 
Designing API for mobile apps (MobileWarsaw 19.01.2015)
Designing API for mobile apps (MobileWarsaw 19.01.2015)Designing API for mobile apps (MobileWarsaw 19.01.2015)
Designing API for mobile apps (MobileWarsaw 19.01.2015)
 
Build Features, Not Apps
Build Features, Not AppsBuild Features, Not Apps
Build Features, Not Apps
 

Similar to Designing an API for Mobile

Network
NetworkNetwork
Network
Ynon Perek
 
Scaling habits of ASP.NET
Scaling habits of ASP.NETScaling habits of ASP.NET
Scaling habits of ASP.NET
David Giard
 
Asynchronous web-development with Python
Asynchronous web-development with PythonAsynchronous web-development with Python
Asynchronous web-development with Python
Skoobe
 
Building real time applications with Symfony2
Building real time applications with Symfony2Building real time applications with Symfony2
Building real time applications with Symfony2
Antonio Peric-Mazar
 
Asynchronous web-development with Python
Asynchronous web-development with PythonAsynchronous web-development with Python
Asynchronous web-development with Python
Anton Caceres
 
«Real Time» Web Applications with SignalR in ASP.NET
«Real Time» Web Applications with SignalR in ASP.NET«Real Time» Web Applications with SignalR in ASP.NET
«Real Time» Web Applications with SignalR in ASP.NET
Alessandro Giorgetti
 
Real time web: is there a life without socket.io and node.js?
Real time web: is there a life without socket.io and node.js?Real time web: is there a life without socket.io and node.js?
Real time web: is there a life without socket.io and node.js?
Eduard Trayan
 
Cloud Connected Devices on a Global Scale (CPN303) | AWS re:Invent 2013
Cloud Connected Devices on a Global Scale (CPN303) | AWS re:Invent 2013Cloud Connected Devices on a Global Scale (CPN303) | AWS re:Invent 2013
Cloud Connected Devices on a Global Scale (CPN303) | AWS re:Invent 2013
Amazon Web Services
 
From 100s to 100s of Millions
From 100s to 100s of MillionsFrom 100s to 100s of Millions
From 100s to 100s of Millions
Erik Onnen
 
RESTful web
RESTful webRESTful web
RESTful web
Alvin Qi
 
Building high performance microservices in finance with Apache Thrift
Building high performance microservices in finance with Apache ThriftBuilding high performance microservices in finance with Apache Thrift
Building high performance microservices in finance with Apache Thrift
RX-M Enterprises LLC
 
How to deliver rich, real-time apps - AppsWorld 2014
How to deliver rich, real-time apps - AppsWorld 2014How to deliver rich, real-time apps - AppsWorld 2014
How to deliver rich, real-time apps - AppsWorld 2014
Andy Piper
 
Eric Proegler Oredev Performance Testing in New Contexts
Eric Proegler Oredev Performance Testing in New ContextsEric Proegler Oredev Performance Testing in New Contexts
Eric Proegler Oredev Performance Testing in New Contexts
Eric Proegler
 
Performance Evaluation of XMPP on the Web
Performance Evaluation of XMPP on the WebPerformance Evaluation of XMPP on the Web
Performance Evaluation of XMPP on the Web
Markku Laine
 
Computer Networks Module 1-part 1.pdf
Computer Networks Module 1-part 1.pdfComputer Networks Module 1-part 1.pdf
Computer Networks Module 1-part 1.pdf
ShanthalaKV
 
SenchaCon 2016: How to Give your Sencha App Real-time Web Performance - James...
SenchaCon 2016: How to Give your Sencha App Real-time Web Performance - James...SenchaCon 2016: How to Give your Sencha App Real-time Web Performance - James...
SenchaCon 2016: How to Give your Sencha App Real-time Web Performance - James...
Sencha
 
Realtime traffic analyser
Realtime traffic analyserRealtime traffic analyser
Realtime traffic analyser
Alex Moskvin
 
Async event based web server
Async event based web serverAsync event based web server
Async event based web server
Gi Woong Lee
 
KKBOX WWDC17 Security - Antony
KKBOX WWDC17 Security - AntonyKKBOX WWDC17 Security - Antony
KKBOX WWDC17 Security - Antony
Liyao Chen
 
Building A Great API - Evan Cooke, Cloudstock, December 2010
Building A Great API - Evan Cooke, Cloudstock, December 2010Building A Great API - Evan Cooke, Cloudstock, December 2010
Building A Great API - Evan Cooke, Cloudstock, December 2010
Twilio Inc
 

Similar to Designing an API for Mobile (20)

Network
NetworkNetwork
Network
 
Scaling habits of ASP.NET
Scaling habits of ASP.NETScaling habits of ASP.NET
Scaling habits of ASP.NET
 
Asynchronous web-development with Python
Asynchronous web-development with PythonAsynchronous web-development with Python
Asynchronous web-development with Python
 
Building real time applications with Symfony2
Building real time applications with Symfony2Building real time applications with Symfony2
Building real time applications with Symfony2
 
Asynchronous web-development with Python
Asynchronous web-development with PythonAsynchronous web-development with Python
Asynchronous web-development with Python
 
«Real Time» Web Applications with SignalR in ASP.NET
«Real Time» Web Applications with SignalR in ASP.NET«Real Time» Web Applications with SignalR in ASP.NET
«Real Time» Web Applications with SignalR in ASP.NET
 
Real time web: is there a life without socket.io and node.js?
Real time web: is there a life without socket.io and node.js?Real time web: is there a life without socket.io and node.js?
Real time web: is there a life without socket.io and node.js?
 
Cloud Connected Devices on a Global Scale (CPN303) | AWS re:Invent 2013
Cloud Connected Devices on a Global Scale (CPN303) | AWS re:Invent 2013Cloud Connected Devices on a Global Scale (CPN303) | AWS re:Invent 2013
Cloud Connected Devices on a Global Scale (CPN303) | AWS re:Invent 2013
 
From 100s to 100s of Millions
From 100s to 100s of MillionsFrom 100s to 100s of Millions
From 100s to 100s of Millions
 
RESTful web
RESTful webRESTful web
RESTful web
 
Building high performance microservices in finance with Apache Thrift
Building high performance microservices in finance with Apache ThriftBuilding high performance microservices in finance with Apache Thrift
Building high performance microservices in finance with Apache Thrift
 
How to deliver rich, real-time apps - AppsWorld 2014
How to deliver rich, real-time apps - AppsWorld 2014How to deliver rich, real-time apps - AppsWorld 2014
How to deliver rich, real-time apps - AppsWorld 2014
 
Eric Proegler Oredev Performance Testing in New Contexts
Eric Proegler Oredev Performance Testing in New ContextsEric Proegler Oredev Performance Testing in New Contexts
Eric Proegler Oredev Performance Testing in New Contexts
 
Performance Evaluation of XMPP on the Web
Performance Evaluation of XMPP on the WebPerformance Evaluation of XMPP on the Web
Performance Evaluation of XMPP on the Web
 
Computer Networks Module 1-part 1.pdf
Computer Networks Module 1-part 1.pdfComputer Networks Module 1-part 1.pdf
Computer Networks Module 1-part 1.pdf
 
SenchaCon 2016: How to Give your Sencha App Real-time Web Performance - James...
SenchaCon 2016: How to Give your Sencha App Real-time Web Performance - James...SenchaCon 2016: How to Give your Sencha App Real-time Web Performance - James...
SenchaCon 2016: How to Give your Sencha App Real-time Web Performance - James...
 
Realtime traffic analyser
Realtime traffic analyserRealtime traffic analyser
Realtime traffic analyser
 
Async event based web server
Async event based web serverAsync event based web server
Async event based web server
 
KKBOX WWDC17 Security - Antony
KKBOX WWDC17 Security - AntonyKKBOX WWDC17 Security - Antony
KKBOX WWDC17 Security - Antony
 
Building A Great API - Evan Cooke, Cloudstock, December 2010
Building A Great API - Evan Cooke, Cloudstock, December 2010Building A Great API - Evan Cooke, Cloudstock, December 2010
Building A Great API - Evan Cooke, Cloudstock, December 2010
 

Recently uploaded

Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTSHeap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Soumen Santra
 
Generative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of contentGenerative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of content
Hitesh Mohapatra
 
Low power architecture of logic gates using adiabatic techniques
Low power architecture of logic gates using adiabatic techniquesLow power architecture of logic gates using adiabatic techniques
Low power architecture of logic gates using adiabatic techniques
nooriasukmaningtyas
 
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
Mukeshwaran Balu
 
PPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testingPPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testing
anoopmanoharan2
 
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdfTutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
aqil azizi
 
ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024
Rahul
 
6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
ClaraZara1
 
Unbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptxUnbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptx
ChristineTorrepenida1
 
basic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdfbasic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdf
NidhalKahouli2
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
obonagu
 
Modelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdfModelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdf
camseq
 
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming PipelinesHarnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Christina Lin
 
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECTCHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
jpsjournal1
 
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
ihlasbinance2003
 
Series of visio cisco devices Cisco_Icons.ppt
Series of visio cisco devices Cisco_Icons.pptSeries of visio cisco devices Cisco_Icons.ppt
Series of visio cisco devices Cisco_Icons.ppt
PauloRodrigues104553
 
bank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdfbank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdf
Divyam548318
 
原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样
原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样
原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样
obonagu
 
digital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdfdigital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdf
drwaing
 
PROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.ppt
PROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.pptPROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.ppt
PROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.ppt
bhadouriyakaku
 

Recently uploaded (20)

Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTSHeap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
 
Generative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of contentGenerative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of content
 
Low power architecture of logic gates using adiabatic techniques
Low power architecture of logic gates using adiabatic techniquesLow power architecture of logic gates using adiabatic techniques
Low power architecture of logic gates using adiabatic techniques
 
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
 
PPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testingPPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testing
 
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdfTutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
 
ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024
 
6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
 
Unbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptxUnbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptx
 
basic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdfbasic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdf
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
 
Modelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdfModelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdf
 
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming PipelinesHarnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
 
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECTCHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
 
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
 
Series of visio cisco devices Cisco_Icons.ppt
Series of visio cisco devices Cisco_Icons.pptSeries of visio cisco devices Cisco_Icons.ppt
Series of visio cisco devices Cisco_Icons.ppt
 
bank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdfbank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdf
 
原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样
原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样
原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样
 
digital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdfdigital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdf
 
PROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.ppt
PROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.pptPROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.ppt
PROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.ppt
 

Designing an API for Mobile

  • 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?