Top Banner
Boxcars and Cabooses When one more XHR is too much Peter Chittum Developer Evangelist @pchittum github.com/pchittum Cleaning up your CRUDdy API
52

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

Apr 14, 2017

Download

Technology

Codemotion
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Boxcars and Cabooses: When one more XHR is too much - Peter Chittum - Codemotion Amsterdam 2016

Boxcars and Cabooses When one more XHR is too much

Peter Chittum Developer Evangelist @pchittum github.com/pchittum

Cleaning up your CRUDdy API

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

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.

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

?

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

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

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

Force.com - Employee Facing Apps  

Apps

HR Product Supply Chain IT Finance Ops

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

Multi Tenant

150k customers 40 Prod POD’s 40 Prod DB’s

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

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

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

It’s About the API

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

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

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

 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

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

Automatic REST Endpoint Creation

 POST

/services/data/v35.0/sobjects/Account

BODY: {

"Name" : "CodeMotion Amsterdam",

"BillingCountry" : "Netherlands"

}

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

Create Record

 POST

/services/data/v35.0/sobjects/Account

BODY: {

"Name" : "CodeMotion Amsterdam",

"BillingCountry" : "Netherlands"

}

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

Fetch Record  GET

/services/data/v35.0/sobjects/Account/0012400000NBMWyAAP

SUCCESS RESPONSE: {

"attributes" : {"type" : "Account”,"url" : "...”},

"Id" : "0012400000NBMWyAAP",

"Name" : "CodeMotion Amsterdam",

"BillingCountry" : "Netherlands",

...

}

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

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",...},

{...}, ...]}

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

Describe (Discover)  GET

/services/data/v35.0/sobjects/Account/describe

SUCCESS RESPONSE: {

...

"queryable" : true,

"searchable" : true,

"updateable" : true,

...

}

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

Limits  GET

/services/data/v35.0/limits

SUCCESS RESPONSE: {

...

"DailyBulkApiRequests": {"Max" : 5000,"Remaining" : 5000},

"DailyStreamingApiEvents": {"Max" : 10000,"Remaining" : 9996},

"DataStorageMB" : {"Max" : 5,"Remaining" : 5},

...

}

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

Many Requests Many Server Trips

POST Record

GET Server Gen Data

GET API Limits

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

Composite Batch REST API

.../composite/batch POST Batch

{ "batchRequests":[ {POST}, {GET}, {GET} ] }

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

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"   }]  }

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

Sample Batch Response Object

 {   "hasErrors": false,   "results": [   { "statusCode": 201, "result": {...} },   { "statusCode": 200, "result": {...} },   { "statusCode": 200, "result": {...} }   ]  }

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

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

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

Hierarchy

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

Parent/Child Related Data

POST Account

POST related Contacts

POST related Cases

RESP: Account ID

RESP: Contact IDs

RESP: Case IDs

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

Composite Tree REST API

.../composite/tree/entity

POST Tree

”records":[ {parent1}, {parent2}, {parent3} ]

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

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"},   "" : "", "" : "", "" : ""}   ...]}, }}, ...] }

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

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"},   "" : "", "" : "", "" : ""}   ...]}, }}, ...] }

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

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"},   "" : "", "" : "", "" : ""}   ...]}, }}, ...] }

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

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"},   "" : "", "" : "", "" : ""}   ...]}, }}, ...] }

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

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"},   "" : "", "" : "", "" : ""}   ...]}, }}, ...] }

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

Demo

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

The (Near) Future

 Extension of Batch and Composite

 Outputs from one sub request to be used as inputs for the another

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

Possible Future Features

 Parameter-based values

 Basic orchestration baked into /batch

 Updates on /tree

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

The Client Problem

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

Aura and Lightning Component Framework

Lightning Component Framework

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

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

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

The Composite App

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

Many Components Many Server Trips

XMLHttpRequest

XMLHttpRequest

XMLHttpRequest

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

Actions: Interact with the Server

•  Apex Method Surfaced to Lightning Components •  @AuraEnabled annotation

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

Boxcarring: Many Actions, One XHR

Action S

ervice

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

Caboose: Postpone High Volume Actions

Action S

ervice •  Defer High-Volume Actions •  Action.setCaboose()

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

Action Service: Server Side API  Apex: Code on Force.com

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

Action Service Client API

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

Upcoming Features

 Integration of offline data store with Action service

 Ability to prioritize actions

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

Takeaways

 Minimize server requests

 Optimize CRUD-based APIs with aggregation

 Optimize creation of hierarchical data

 Client-side libraries to support request batching

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

 Meetup: bit.ly/ams-sf-devs

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

 startups.salesforce.com

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

 trailhead.com

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

Q & A Peter Chittum Developer Evangelist @pchittum github.com/pchittum

 Learn: developer.salesforce.com/trailhead

 Meetup: bit.ly/ams-sf-devs

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

Thank you