Mobile apps & Server
APIs, the weak link?
Summary

1. Why going for mobile?
Summary

1. Why going for mobile?

2. The Viadeo mobile app
Summary

1. Why going for mobile?

2. The Viadeo mobile app

3. Are mobile applications only a client?
Summary

1. Why going for mobile?

2. The Viadeo mobile app

3. Are mobile applications only a client?

4. Our architecture
Summary

1. Why going for mobile?

2. The Viadeo mobile app

3. Are mobile applications only a client?

4. Our architecture

5. Issues to face
Internet is changing
    From here …        to there !
GLOBAL MOBILE TRAFFIC GROWING RAPIDLY TO REACH
10% OF INTERNET TRAFFIC
SMARTPHONE USER ADOPTION HAS
HUGE UPSIDE POTENTIAL
GOOD NEWS:
MONETIZATION ALSO GROWING RAPIDLY
MOBILE IN VIADEO




          Viadeo mobile                  Tianji mobile

          Improve user                  Improve user
      experience with mobile        experience with mobile




                     Mobile labs
                Launch new apps to boost traffic
NEW: VIADEO MOBILE BUSINESS UNIT


→ Go Fast !
→ Autonomous - not independant ;-)
→ Lean Startup mode
THE VIADEO APPLICATION




              The video
THE USER WANTS…


1. No crash!
THE USER WANTS…


1. No crash!

2. A fast application
THE USER WANTS…


1. No crash!

2. A fast application

3. Small traffic and save battery life
THE USER WANTS…


1. No crash!

2. A fast application

3. Small traffic and save battery life

4. Security
USER WANTS A SUPER APP




 ONLY FOCUS ON CLIENT
  SIDE DEVELOPMENT?
FOCUS ON CLIENT SIDE

1. Native vs HTML5

2. Design and ergonomy

3. Responsive interface

4. Follow guidelines
BUT…

Limited capabilities of the devices
BUT…

Limited capabilities of the devices




   GREAT
BUT…

Limited capabilities of the devices




                  BUT




   GREAT
BUT…

Limited capabilities of the devices




                  BUT




   GREAT                      NOT SO GREAT
FEATURE PHONES?
ARE THEY IMPORTANT?
BUT…

Slow and unreliable network

1. 4G
BUT…

Slow and unreliable network

1. 4G

2. 3G
BUT…

Slow and unreliable network

1. 4G

2. 3G

3. EDGE
BUT…

Slow and unreliable network

1. 4G

2. 3G

3. EDGE

4. GPRS
FOCUS ON THE SERVER SIDE




   A GREAT CLIENT
APPLICATION BEGINS ON
     SERVER SIDE
TO BE CONSIDERED

1. API sends a lot of data (XML/JSON) ->
   my feed of news can be 60kb
TO BE CONSIDERED

1. API sends a lot of data (XML/JSON) ->
   my feed of news can be 60kb

2. Mobile applications need to reduce
   number of requests to get data
TO BE CONSIDERED

1. API sends a lot of data (XML/JSON) ->
   my feed of news can be 60kb

2. Mobile applications need to reduce
   number of requests to get data

3. API needs to serve millions of mobile
   devices
WHAT CAN WE DO?

1. Transform, filter and compress data
WHAT CAN WE DO?

1. Transform, filter and compress data

2. Aggregate calls on server side
WHAT CAN WE DO?

1. Transform, filter and compress data

2. Aggregate calls on server side

3. Scalable architecture
VIADEO MOBILE ARCHITECTURE




                       VIADEO API
                                    MEMCACHE,
                                    DATABASE, …
VIADEO MOBILE ARCHITECTURE




           MIDDLE END
                 or       VIADEO API
           MOBILE API                    MEMCACHE,
                           (6 servers)
            (2 servers)                  DATABASE, …
NodeJS

1. Small memory footprint
NodeJS

1. Small memory footprint

2. Event driven architecture (single event
   loop vs multiple blocking threads)
NodeJS
NodeJS

1. Small memory footprint

2. Event driven architecture (single event
   loop vs multiple blocking threads)

3. Great to work with JSON
Middlend usage example

SMARTNEWS
Middlend usage example

SMARTNEWS

News proposed targeting your
areas of interest.

More you use Viadeo, more the
smartnews will be accurate
Middlend usage example

SMARTNEWS

News proposed targeting your
areas of interest.

More you use Viadeo, more the
smartnews will be accurate



The JSON data in the next slide is what
the API sends for a single news
Middlend usage example
Middlend usage example
EVERYTHING IS OK?

DOWNLOAD OF THE CONTACTS LIST

After the login, the application starts to
download the complete list of your Viadeo
contacts
EVERYTHING IS OK?

DOWNLOAD OF THE CONTACTS LIST

After the login, the application starts to
download the complete list of your Viadeo
contacts
EVERYTHING IS OK?

  DOWNLOAD OF THE CONTACTS LIST

  After the login, the application starts to
  download the complete list of your Viadeo
  contacts



Some users have contacts list with thousands of contacts
Problem

Middleend makes parallel calls to the API
to get the contacts list and send back to
the user:

      Parallel calls of 200 contacts




User with 5000 contacts = 25 calls x 200
               contacts
Test



Test of the preprod platform
with many parallel calls gives
      you good results
Problem

   Launch of new iPhone application
Problem

   Launch of new iPhone application



  Big traffic increase and many calls to
        download the contact list
Problem

   Launch of new iPhone application



  Big traffic increase and many calls to
        download the contact list



 Access time to memcache and database
                increases
Problem
                                            Avg. Response time (ms)
16000



14000



12000



10000



8000



6000



4000



2000



    0
        10:30   10:31   10:32   10:33   10:34   10:35   10:36   10:37   10:38   10:39   10:40   10:41   10:42   10:43   10:44
Problem


               RESULT:

  Access to memcache and database is
        very slow or impossible



      The application doesn’t work
What’s going on?

• Put useful information about performances
  in your log

• Use good realtime analysis tools
  • AppDynamics
  • Splunk

• Use data mining tools
  • Datameer

• Setup alert system to get warned about
  performance issues
Source of the problems

Your production environment is different
from the preprod environment:

1. Not only mobile traffic on the API
   (widgets)

2. Webapp access to the backend resource

3. Presence of daemon and batches that
   access the memcache or the database
Solutions

1. Optimize the way middleend downloads
   the contact list to decrease charge on API

2. Reduce access to database and
   memcache (code improvements)

3. Optimize calls to the API (reduce
   numbers of calls or data size)

4. Reduce the impact of other systems
   especially in traffic peak time
Other thoughts around mobile app and API

                 ERROR CODES

Often API are designed to answer only with
HTTP code to notify errors

Enhance your response with data in the JSON
response to allow client to really recognize the
error and show an appropriate message to the
user.

      NOT ONLY 400 (BAD REQUEST)
Other thoughts around mobile app and API



1. Additional error code in the Json response
   and recognize it on application side

2. Add a specific message in the Json
   response that the application can show to
   the user (manage multiple languages)
Other thoughts around mobile app and API

                      VERSIONING
{
"id": "jhAzouiEhDiDoaligeyAAslvAA",
"picture": "http://myphoto.com/images/photos/3749237498/"
}


                WHAT IF I NEED TO CHANGE TO:

{
"id": "jhAzouiEhDiDoaligeyAAslvAA",
"picture_link": "http://myphoto.com/images/photos/3749237498/"
}
Other thoughts around mobile app and API

                  VERSIONING


• Impossible to update all the mobile
  applications at the same time to support the
  new structure

• Server must be able to respond both to old
  and new versions requests
Other thoughts around mobile app and API

                  VERSIONING

• Send both fields?
{
"id": "jhAzouiEhDiDoaligeyAAslvAA",
"picture":
"http://myphoto.com/images/photos/3749237498/"
"picture_link":
"http://myphoto.com/images/photos/3749237498/"
}
Other thoughts around mobile app and API

                      VERSIONING
•   Use the Http «Accept» header: server load the response model
    and serialize the response according to the version 1.0

Accept: /myapplication1.0

{
"id": "jhAzouiEhDiDoaligeyAAslvAA",
"picture": "http://myphoto.com/images/photos/3749237498/"
}



Accept: /myapplication2.0
{
"id": "jhAzouiEhDiDoaligeyAAslvAA",
"picture_link": "http://myphoto.com/images/photos/3749237498/"
}
Other thoughts around mobile app and API

      KEEP CLIENT AUTHENTICATED

• First connection: authenticate your client
  accessing the Database

• Store the information in session and sends
  back the session-id to the client

• Mobile app sends the session-id in the next
  requests

• Server can check the existence of a session
  without accessing the database
MOBILE TEAM IS HIRING




      PASSIONATE ABOUT
           MOBILE?

       SEND US YOUR CV:
        hrit@viadeo.com
Thanks a lot for your attention!

                    Q&A

           Emanuele Pecorari
                  Mobile Architect
             epecorari@viadeoteam.com
http://fr.viadeo.com/en/profile/emanuele.pecorari



                                            © Viadeo 2010

Mobile apps & Server Apis, the weak link? par Emanuele Pecorari

  • 1.
    Mobile apps &Server APIs, the weak link?
  • 2.
  • 3.
    Summary 1. Why goingfor mobile? 2. The Viadeo mobile app
  • 4.
    Summary 1. Why goingfor mobile? 2. The Viadeo mobile app 3. Are mobile applications only a client?
  • 5.
    Summary 1. Why goingfor mobile? 2. The Viadeo mobile app 3. Are mobile applications only a client? 4. Our architecture
  • 6.
    Summary 1. Why goingfor mobile? 2. The Viadeo mobile app 3. Are mobile applications only a client? 4. Our architecture 5. Issues to face
  • 7.
    Internet is changing From here … to there !
  • 8.
    GLOBAL MOBILE TRAFFICGROWING RAPIDLY TO REACH 10% OF INTERNET TRAFFIC
  • 9.
    SMARTPHONE USER ADOPTIONHAS HUGE UPSIDE POTENTIAL
  • 10.
  • 11.
    MOBILE IN VIADEO Viadeo mobile Tianji mobile Improve user Improve user experience with mobile experience with mobile Mobile labs Launch new apps to boost traffic
  • 12.
    NEW: VIADEO MOBILEBUSINESS UNIT → Go Fast ! → Autonomous - not independant ;-) → Lean Startup mode
  • 13.
  • 14.
  • 15.
    THE USER WANTS… 1.No crash! 2. A fast application
  • 16.
    THE USER WANTS… 1.No crash! 2. A fast application 3. Small traffic and save battery life
  • 17.
    THE USER WANTS… 1.No crash! 2. A fast application 3. Small traffic and save battery life 4. Security
  • 18.
    USER WANTS ASUPER APP ONLY FOCUS ON CLIENT SIDE DEVELOPMENT?
  • 19.
    FOCUS ON CLIENTSIDE 1. Native vs HTML5 2. Design and ergonomy 3. Responsive interface 4. Follow guidelines
  • 20.
  • 21.
  • 22.
    BUT… Limited capabilities ofthe devices BUT GREAT
  • 23.
    BUT… Limited capabilities ofthe devices BUT GREAT NOT SO GREAT
  • 24.
  • 25.
  • 26.
  • 27.
    BUT… Slow and unreliablenetwork 1. 4G 2. 3G
  • 28.
    BUT… Slow and unreliablenetwork 1. 4G 2. 3G 3. EDGE
  • 29.
    BUT… Slow and unreliablenetwork 1. 4G 2. 3G 3. EDGE 4. GPRS
  • 30.
    FOCUS ON THESERVER SIDE A GREAT CLIENT APPLICATION BEGINS ON SERVER SIDE
  • 31.
    TO BE CONSIDERED 1.API sends a lot of data (XML/JSON) -> my feed of news can be 60kb
  • 32.
    TO BE CONSIDERED 1.API sends a lot of data (XML/JSON) -> my feed of news can be 60kb 2. Mobile applications need to reduce number of requests to get data
  • 33.
    TO BE CONSIDERED 1.API sends a lot of data (XML/JSON) -> my feed of news can be 60kb 2. Mobile applications need to reduce number of requests to get data 3. API needs to serve millions of mobile devices
  • 34.
    WHAT CAN WEDO? 1. Transform, filter and compress data
  • 35.
    WHAT CAN WEDO? 1. Transform, filter and compress data 2. Aggregate calls on server side
  • 36.
    WHAT CAN WEDO? 1. Transform, filter and compress data 2. Aggregate calls on server side 3. Scalable architecture
  • 37.
    VIADEO MOBILE ARCHITECTURE VIADEO API MEMCACHE, DATABASE, …
  • 38.
    VIADEO MOBILE ARCHITECTURE MIDDLE END or VIADEO API MOBILE API MEMCACHE, (6 servers) (2 servers) DATABASE, …
  • 39.
  • 40.
    NodeJS 1. Small memoryfootprint 2. Event driven architecture (single event loop vs multiple blocking threads)
  • 41.
  • 42.
    NodeJS 1. Small memoryfootprint 2. Event driven architecture (single event loop vs multiple blocking threads) 3. Great to work with JSON
  • 43.
  • 44.
    Middlend usage example SMARTNEWS Newsproposed targeting your areas of interest. More you use Viadeo, more the smartnews will be accurate
  • 45.
    Middlend usage example SMARTNEWS Newsproposed targeting your areas of interest. More you use Viadeo, more the smartnews will be accurate The JSON data in the next slide is what the API sends for a single news
  • 46.
  • 47.
  • 48.
    EVERYTHING IS OK? DOWNLOADOF THE CONTACTS LIST After the login, the application starts to download the complete list of your Viadeo contacts
  • 49.
    EVERYTHING IS OK? DOWNLOADOF THE CONTACTS LIST After the login, the application starts to download the complete list of your Viadeo contacts
  • 50.
    EVERYTHING IS OK? DOWNLOAD OF THE CONTACTS LIST After the login, the application starts to download the complete list of your Viadeo contacts Some users have contacts list with thousands of contacts
  • 51.
    Problem Middleend makes parallelcalls to the API to get the contacts list and send back to the user: Parallel calls of 200 contacts User with 5000 contacts = 25 calls x 200 contacts
  • 52.
    Test Test of thepreprod platform with many parallel calls gives you good results
  • 53.
    Problem Launch of new iPhone application
  • 54.
    Problem Launch of new iPhone application Big traffic increase and many calls to download the contact list
  • 55.
    Problem Launch of new iPhone application Big traffic increase and many calls to download the contact list Access time to memcache and database increases
  • 56.
    Problem Avg. Response time (ms) 16000 14000 12000 10000 8000 6000 4000 2000 0 10:30 10:31 10:32 10:33 10:34 10:35 10:36 10:37 10:38 10:39 10:40 10:41 10:42 10:43 10:44
  • 57.
    Problem RESULT: Access to memcache and database is very slow or impossible The application doesn’t work
  • 58.
    What’s going on? •Put useful information about performances in your log • Use good realtime analysis tools • AppDynamics • Splunk • Use data mining tools • Datameer • Setup alert system to get warned about performance issues
  • 59.
    Source of theproblems Your production environment is different from the preprod environment: 1. Not only mobile traffic on the API (widgets) 2. Webapp access to the backend resource 3. Presence of daemon and batches that access the memcache or the database
  • 60.
    Solutions 1. Optimize theway middleend downloads the contact list to decrease charge on API 2. Reduce access to database and memcache (code improvements) 3. Optimize calls to the API (reduce numbers of calls or data size) 4. Reduce the impact of other systems especially in traffic peak time
  • 61.
    Other thoughts aroundmobile app and API ERROR CODES Often API are designed to answer only with HTTP code to notify errors Enhance your response with data in the JSON response to allow client to really recognize the error and show an appropriate message to the user. NOT ONLY 400 (BAD REQUEST)
  • 62.
    Other thoughts aroundmobile app and API 1. Additional error code in the Json response and recognize it on application side 2. Add a specific message in the Json response that the application can show to the user (manage multiple languages)
  • 63.
    Other thoughts aroundmobile app and API VERSIONING { "id": "jhAzouiEhDiDoaligeyAAslvAA", "picture": "http://myphoto.com/images/photos/3749237498/" } WHAT IF I NEED TO CHANGE TO: { "id": "jhAzouiEhDiDoaligeyAAslvAA", "picture_link": "http://myphoto.com/images/photos/3749237498/" }
  • 64.
    Other thoughts aroundmobile app and API VERSIONING • Impossible to update all the mobile applications at the same time to support the new structure • Server must be able to respond both to old and new versions requests
  • 65.
    Other thoughts aroundmobile app and API VERSIONING • Send both fields? { "id": "jhAzouiEhDiDoaligeyAAslvAA", "picture": "http://myphoto.com/images/photos/3749237498/" "picture_link": "http://myphoto.com/images/photos/3749237498/" }
  • 66.
    Other thoughts aroundmobile app and API VERSIONING • Use the Http «Accept» header: server load the response model and serialize the response according to the version 1.0 Accept: /myapplication1.0 { "id": "jhAzouiEhDiDoaligeyAAslvAA", "picture": "http://myphoto.com/images/photos/3749237498/" } Accept: /myapplication2.0 { "id": "jhAzouiEhDiDoaligeyAAslvAA", "picture_link": "http://myphoto.com/images/photos/3749237498/" }
  • 67.
    Other thoughts aroundmobile app and API KEEP CLIENT AUTHENTICATED • First connection: authenticate your client accessing the Database • Store the information in session and sends back the session-id to the client • Mobile app sends the session-id in the next requests • Server can check the existence of a session without accessing the database
  • 68.
    MOBILE TEAM ISHIRING PASSIONATE ABOUT MOBILE? SEND US YOUR CV: hrit@viadeo.com
  • 69.
    Thanks a lotfor your attention! Q&A Emanuele Pecorari Mobile Architect epecorari@viadeoteam.com http://fr.viadeo.com/en/profile/emanuele.pecorari © Viadeo 2010