Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Boxcars and Cabooses: When one more XHR is too much - Peter Chittum - Codemotion Amsterdam 2016

262 views

Published on

RESTful APIs have simplified backend access providing clean URL-based resource representations using standard HTTP methods. But growth in the number of these APIs can lead to inefficiencies: if an app needs to access many of these resources at once, performance can bog down. 'Boxcarring' is the bundling together of multiple HTTP requests into one. For example, the client might bundle multiple requests into a single call. On the server, a RESTful API can accept a POST to multiple resources in one request. This talk will demonstrate both client and server side examples of boxcar requests.

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Boxcars and Cabooses: When one more XHR is too much - Peter Chittum - Codemotion Amsterdam 2016

  1. 1. Boxcars and Cabooses When one more XHR is too much Peter Chittum Developer Evangelist @pchittum github.com/pchittum Cleaning up your CRUDdy API
  2. 2. Forward Looking Statement Safe harbor statement under the Private Securities Litigation Reform Act of 1995: This presentation may contain forward-looking statements that involve risks, uncertainties, and assumptions. If any such uncertainties materialize or if any of the assumptions proves incorrect, the results of salesforce.com, inc. could differ materially from the results expressed or implied by the forward- looking statements we make. All statements other than statements of historical fact could be deemed forward-looking, including any projections of product or service availability, subscriber growth, earnings, revenues, or other financial items and any statements regarding strategies or plans of management for future operations, statements of belief, any statements concerning new, planned, or upgraded services or technology developments and customer contracts or use of our services. The risks and uncertainties referred to above include – but are not limited to – risks associated with developing and delivering new functionality for our service, new products and services, our new business model, our past operating losses, possible fluctuations in our operating results and rate of growth, interruptions or delays in our Web hosting, breach of our security measures, the outcome of any litigation, risks associated with completed and any possible mergers and acquisitions, the immature market in which we operate, our relatively limited operating history, our ability to expand, retain, and motivate our employees and manage our growth, new releases of our service and successful customer deployment, our limited history reselling non- salesforce.com products, and utilization and selling to larger enterprise customers. Further information on potential factors that could affect the financial results of salesforce.com, inc. is included in our annual report on Form 10-K for the most recent fiscal year and in our quarterly report on Form 10-Q for the most recent fiscal quarter. These documents and others containing important disclosures are available on the SEC Filings section of the Investor Information section of our Web site. Any unreleased services or features referenced in this or other presentations, press releases or public statements are not currently available and may not be delivered on time or at all. Customers who purchase our services should make the purchase decisions based upon features that are currently available. Salesforce.com, inc. assumes no obligation and does not intend to update these forward-looking statements.
  3. 3. ?
  4. 4. Agile and elastic platform that developers love Smarter infrastructure lets you build apps that scale Open and extensible Modern language support and ecosystem of 150+ add-ons Connected to Force.com Sync customer apps with business processes Build Customer-Facing Apps with Heroku
  5. 5. Force.com - Employee Facing Apps ​  Apps HR Product Supply Chain ITFinanceOps
  6. 6. Multi Tenant 150k customers 40 Prod POD’s 40 Prod DB’s
  7. 7. Pre-Built Apps ​ AppExchange is the #1 Business App Marketplace Customized for Salesforce Trusted and Secure Reviewed by Peers Over 2,800 apps 3 million installs
  8. 8. It’s About the API
  9. 9. Comprehensive Suite of APIs and Toolkits Web Service Endpoint Web Service Endpoint Apex WS/REST Outbound Messaging Business Logic Sync Bulk API Streaming API Topic CRUD Data Bayeux Client Applications and Middleware Java SDK Ruby gem PHP Toolkit Mobile SDK 3rd Party Adapters Apex Callouts
  10. 10. ​ Overall site peak day •  >4 Billion transactions •  200-250 milliseconds average •  ~30% of transactions via API requests Salesforce’s Daily API Performance Yesterday: ??? ​ Source: trust.salesforce.com
  11. 11. Automatic REST Endpoint Creation ​ POST /services/data/v35.0/sobjects/Account BODY: { "Name" : "CodeMotion Amsterdam", "BillingCountry" : "Netherlands" }
  12. 12. Create Record ​ POST /services/data/v35.0/sobjects/Account BODY: { "Name" : "CodeMotion Amsterdam", "BillingCountry" : "Netherlands" }
  13. 13. Fetch Record ​ GET /services/data/v35.0/sobjects/Account/0012400000NBMWyAAP SUCCESS RESPONSE: { "attributes" : {"type" : "Account”,"url" : "...”}, "Id" : "0012400000NBMWyAAP", "Name" : "CodeMotion Amsterdam", "BillingCountry" : "Netherlands", ... }
  14. 14. Query Endpoint ​ GET /services/data/v35.0/query?q=SELECT ... FROM Account WHERE ... SUCCESS RESPONSE: { "totalSize" : 2, "done" : true, "records" : [ {"attributes" : {"type" : "Account","url" : "..."}, "Id" : "0012400000NBMWyAAP", "Name" : "Test 123",...}, {...}, ...]}
  15. 15. Describe (Discover) ​ GET /services/data/v35.0/sobjects/Account/describe SUCCESS RESPONSE: { ... "queryable" : true, "searchable" : true, "updateable" : true, ... }
  16. 16. Limits ​ GET /services/data/v35.0/limits SUCCESS RESPONSE: { ... "DailyBulkApiRequests": {"Max" : 5000,"Remaining" : 5000}, "DailyStreamingApiEvents": {"Max" : 10000,"Remaining" : 9996}, "DataStorageMB" : {"Max" : 5,"Remaining" : 5}, ... }
  17. 17. Many Requests Many Server Trips POST Record GET Server Gen Data GET API Limits
  18. 18. Composite Batch REST API .../composite/batch POST Batch { "batchRequests":[ {POST}, {GET}, {GET} ] }
  19. 19. Sample Batch Request ​ POST: <salesforcedomain>/services/data/v35.0/composite/batch ​ {"batchRequests" : [ ​  {"method" : "POST", ​  "url" : "v35.0/sobjects/account/", ​  "richInput" : {"Name" : "NewName", "Industry" : "Tech"}}, ​  {"method" : "GET", ​  "url" : "v35.0/query?q=select id, name, industry from account ​  order by createddate desc limit 10"}, ​  {"method" : "GET", ​  "url" : "v35.0/limits" ​  }] ​ }
  20. 20. Sample Batch Response Object ​ { ​  "hasErrors": false, ​  "results": [ ​  { "statusCode": 201, "result": {...} }, ​  { "statusCode": 200, "result": {...} }, ​  { "statusCode": 200, "result": {...} } ​  ] ​ }
  21. 21. Batch Request Behavior •  Resource which accepts multiple REST calls to execute •  Up to 25 sub-requests •  URI, Method, and optional Body •  Sub-requests can be unrelated API calls •  Sub-requests are executed serially, in order, and as the running user •  Commit each subrequest on completion •  Optional parameter: haltOnError •  Do not continue after error occurs •  But check subrequests for errors
  22. 22. Hierarchy
  23. 23. Parent/Child Related Data POST Account POST related Contacts POST related Cases RESP: Account ID RESP: Contact IDs RESP: Case IDs
  24. 24. Composite Tree REST API .../composite/tree/entity POST Tree ”records":[ {parent1}, {parent2}, {parent3} ]
  25. 25. Sample Tree Request ​ POST: <salesforcedomain>/services/data/v35.0/composite/tree/Account ​ {"records" :[ ​  {"attributes": {"type":"Account", "referenceId":"ref1"}, ​  "name" : "CodeMotion", "phone" : "1234567890", ​  "type" : "Customer", "industry" : "Events", ​  "Contacts" : { ​  "records" : [ ​  {"attributes": {"type":"Contact", "referenceId":"ref2"}, ​  "lastname" : "Smith", "title" : "Organizer"}, ​  ...]}, ​  "Cases" : { ​  "records" : [ ​  {"attributes": {"type":"Case", "referenceId":"ref3"}, ​  "" : "", "" : "", "" : ""} ​  ...]}, }}, ...] }
  26. 26. Sample Tree Request: Many Records ​ POST: <salesforcedomain>/services/data/v35.0/composite/tree/Account ​ {"records" :[ ​  {"attributes": {"type":"Account", "referenceId":"ref1"}, ​  "name" : "CodeMotion", "phone" : "1234567890", ​  "type" : "Customer", "industry" : "Events", ​  "Contacts" : { ​  "records" : [ ​  {"attributes": {"type":"Contact", "referenceId":"ref2"}, ​  "lastname" : "Smith", "title" : "Organizer"}, ​  ...]}, ​  "Cases" : { ​  "records" : [ ​  {"attributes": {"type":"Case", "referenceId":"ref3"}, ​  "" : "", "" : "", "" : ""} ​  ...]}, }}, ...] }
  27. 27. Sample Tree Request: Parent Record ​ POST: <salesforcedomain>/services/data/v35.0/composite/tree/Account ​ {"records" :[ ​  {"attributes": {"type":"Account", "referenceId":"ref1"}, ​  "name" : "CodeMotion", "phone" : "1234567890", ​  "type" : "Customer", "industry" : "Events", ​  "Contacts" : { ​  "records" : [ ​  {"attributes": {"type":"Contact", "referenceId":"ref2"}, ​  "lastname" : "Smith", "title" : "Organizer"}, ​  ...]}, ​  "Cases" : { ​  "records" : [ ​  {"attributes": {"type":"Case", "referenceId":"ref3"}, ​  "" : "", "" : "", "" : ""} ​  ...]}, }}, ...] }
  28. 28. Sample Tree Request: Child Records ​ POST: <salesforcedomain>/services/data/v35.0/composite/tree/Account ​ {"records" :[ ​  {"attributes": {"type":"Account", "referenceId":"ref1"}, ​  "name" : "CodeMotion", "phone" : "1234567890", ​  "type" : "Customer", "industry" : "Events", ​  "Contacts" : { ​  "records" : [ ​  {"attributes": {"type":"Contact", "referenceId":"ref2"}, ​  "lastname" : "Smith", "title" : "Organizer"}, ​  ...]}, ​  "Cases" : { ​  "records" : [ ​  {"attributes": {"type":"Case", "referenceId":"ref3"}, ​  "" : "", "" : "", "" : ""} ​  ...]}, }}, ...] }
  29. 29. Sample Tree Request: Client Ids ​ POST: <salesforcedomain>/services/data/v35.0/composite/tree/Account ​ {"records" :[ ​  {"attributes": {"type":"Account", "referenceId":"ref1"}, ​  "name" : "CodeMotion", "phone" : "1234567890", ​  "type" : "Analyst", "industry" : "Events", ​  "Contacts" : { ​  "records" : [ ​  {"attributes": {"type":"Contact", "referenceId":"ref2"}, ​  "lastname" : "Smith", "title" : "Organizer"}, ​  ...]}, ​  "Cases" : { ​  "records" : [ ​  {"attributes": {"type":"Case", "referenceId":"ref3"}, ​  "" : "", "" : "", "" : ""} ​  ...]}, }}, ...] }
  30. 30. Demo
  31. 31. The (Near) Future ​ Extension of Batch and Composite ​ Outputs from one sub request to be used as inputs for the another
  32. 32. Possible Future Features ​ Parameter-based values ​ Basic orchestration baked into /batch ​ Updates on /tree
  33. 33. The Client Problem
  34. 34. Aura and Lightning Component Framework Lightning Component Framework
  35. 35. Lightning Component Design Principles •  Component author namespacing •  Automatic component-based CSS namespacing •  Everything is a component •  Allow for programmatic or point-and-click UI composition •  Enable Salesforce, customers, and partners to build composite UIs •  Works on any form factor
  36. 36. The Composite App
  37. 37. Many Components Many Server Trips XMLHttpRequest XMLHttpRequest XMLHttpRequest
  38. 38. Actions: Interact with the Server •  Apex Method Surfaced to Lightning Components •  @AuraEnabled annotation
  39. 39. Boxcarring: Many Actions, One XHR ActionService
  40. 40. Caboose: Postpone High Volume Actions ActionService •  Defer High-Volume Actions •  Action.setCaboose()
  41. 41. Action Service: Server Side API ​ Apex: Code on Force.com
  42. 42. Action Service Client API
  43. 43. Upcoming Features ​ Integration of offline data store with Action service ​ Ability to prioritize actions
  44. 44. Takeaways ​ Minimize server requests ​ Optimize CRUD-based APIs with aggregation ​ Optimize creation of hierarchical data ​ Client-side libraries to support request batching
  45. 45. ​ Meetup: bit.ly/ams-sf-devs
  46. 46. ​ startups.salesforce.com
  47. 47. ​ trailhead.com
  48. 48. Q & A Peter Chittum Developer Evangelist @pchittum github.com/pchittum ​ Learn: developer.salesforce.com/trailhead ​ Meetup: bit.ly/ams-sf-devs
  49. 49. Thank you

×