Download - I Love APIs 2015: Building Predictive Apps with Lamda and MicroServices

Transcript
Page 1: I Love APIs 2015: Building Predictive Apps with Lamda and MicroServices

1

Building predictive apps with λ & μ-services architecture #Alan Ho @karlunho

Director of Product

Page 2: I Love APIs 2015: Building Predictive Apps with Lamda and MicroServices

Context is King

2

Page 3: I Love APIs 2015: Building Predictive Apps with Lamda and MicroServices

Technology Choices Today

3

Datawarehouse RDBMS J2EE AppServer

Page 4: I Love APIs 2015: Building Predictive Apps with Lamda and MicroServices

Lambda Architecture

4

Page 5: I Love APIs 2015: Building Predictive Apps with Lamda and MicroServices

What is Context ?

5

Historical #Events#

Recent#Events#

Now#

Page 6: I Love APIs 2015: Building Predictive Apps with Lamda and MicroServices

Lambda Architecture

6

Batch Storage

Near RT Storage

Batch Processing

(MR)

Near RealTime

Processing

Query DB

Batch Layer# Serving Layer#

Speed Layer#

APIs

Direct Mail

Email

Web

Mobile

Outreach

Req / Res Processing

Historical Events

Recent Events

Page 7: I Love APIs 2015: Building Predictive Apps with Lamda and MicroServices

Netflix

7

Page 8: I Love APIs 2015: Building Predictive Apps with Lamda and MicroServices

•  Offline = Batch Layer

•  Nearline = Speed Layer

•  Online = Serving Layer

Page 9: I Love APIs 2015: Building Predictive Apps with Lamda and MicroServices

Batch Layer (Offline) •  Singular Value

Decomposition

•  Batch like operations

•  High algorithm complexity

•  Results Flow into Cassandra

Page 10: I Love APIs 2015: Building Predictive Apps with Lamda and MicroServices

Speed Layer (Near Line)

10

•  Medium request/response

•  Medium data

•  Medium algorithm complexity

•  Intermediate caching, incremental learning algos

Page 11: I Love APIs 2015: Building Predictive Apps with Lamda and MicroServices

Serving layer (Online)

• Fast request/response, performance is key – high availability/SLA

• Fallback mechanism to Nearline/Offline operations

• Low algorithm complexity

Page 12: I Love APIs 2015: Building Predictive Apps with Lamda and MicroServices

Final Thoughts: •  Very complete system

•  Very custom and high performance

•  Lots of specialized systems for specialized tasks

•  Not practical for most enterprises

Page 13: I Love APIs 2015: Building Predictive Apps with Lamda and MicroServices

Microservices & LambdaArchitecture

13

Page 14: I Love APIs 2015: Building Predictive Apps with Lamda and MicroServices

App Explosion

14

How can I embed context-awareness in all customer experiences?

Page 15: I Love APIs 2015: Building Predictive Apps with Lamda and MicroServices

Micro-services

15

Page 16: I Love APIs 2015: Building Predictive Apps with Lamda and MicroServices

Micro-services Best Practice

16

Isolation REST API

HTTP://<Resource>/

Page 17: I Love APIs 2015: Building Predictive Apps with Lamda and MicroServices

Isolation at all tiers

17

Batch Storage

Near RT Storage

Batch Processing

(MR)

Near RealTime

Processing

Query DB

APIs

Direct Mail

Email

Web

Mobile

Outreach

Req / Res Processing

Historical Events

Recent Events

Batch Processing

(MR)

Near RealTime

Processing

Req / Res Processing

Batch Processing

(MR)

Near RealTime

Processing

Req / Res Processing

Batch Processing

(MR)

Near RealTime

Processing

Req / Res Processing

Batch Storage

Near RT Storage

Query DB

Batch Storage

Near RT Storage

Query DB

YARN Batch Layer# Serving Layer#

Page 18: I Love APIs 2015: Building Predictive Apps with Lamda and MicroServices

API at all tiers

18

Batch Layer# Serving Layer#

Speed Layer#

Direct Mail

Email

Web

Mobile

Outreach

/Scores#

/Counts#

/Recommendations#

Historical Events

Recent Events

Page 19: I Love APIs 2015: Building Predictive Apps with Lamda and MicroServices

Real-time Scoring for Recommendations

19

Page 20: I Love APIs 2015: Building Predictive Apps with Lamda and MicroServices

Recommendations Example

20

Page 21: I Love APIs 2015: Building Predictive Apps with Lamda and MicroServices

Real-time Scoring Architecture

21

Hadoop

In-Memory

Insights (GRASP)

Node.js

Node.js API BaaS

(APIs)

Direct Mail

Email

Web

Mobile

Outreach

(Batch Scores)

(Activities / Counters)

(Query)

Historical Events

Realtime Events

(Context)

Backend

(Mashup)

3 4

5

1

2 6

Node.js

Page 22: I Love APIs 2015: Building Predictive Apps with Lamda and MicroServices

Batch Layer

•  Uses R for building predictive models

•  Algorithms based on Event Sequences

•  Lots and lots of tooling

22

Hadoop Insights (GRASP)

API BaaS

(Batch Scores) 1

Apigee UI

Page 23: I Love APIs 2015: Building Predictive Apps with Lamda and MicroServices

23

R Code#

Page 24: I Love APIs 2015: Building Predictive Apps with Lamda and MicroServices

24

Scored Export to Serving Layer#

Page 25: I Love APIs 2015: Building Predictive Apps with Lamda and MicroServices

Speed Layer

•  Easy to program via node.js

•  Low algorithm complexity – Storm is overkill for most Apigee customers

•  Simple aggregates via C* counters good enough

•  Good for capturing locations, activity stream, etc.

25

Node.js

API BaaS

Apigee UI

Page 26: I Love APIs 2015: Building Predictive Apps with Lamda and MicroServices

BaaS Node.js Counter Example

var event = new Usergrid.Counter(event_options, function (error, result) { … });

// Then we POST the event to increment the countervar counter_options = { name: productName + ’.add_to_cart', value: 1 }event.increment (counter_options, function (error, result)

26

curl -X GET https://api.usergrid.com/my-org/my-app/counters?counter=appleIpad3.add_to_cart

Input code:

Output code:#

Page 27: I Love APIs 2015: Building Predictive Apps with Lamda and MicroServices

Microservices Layer

•  API Layer (Swagger)

•  Context Injection

•  Service Orchestration

•  Fallback logic

27

Node.js Node.js API BaaS

Direct Mail

Email

Web

Mobile

Outreach

(Context)

Backend

Page 28: I Love APIs 2015: Building Predictive Apps with Lamda and MicroServices

Swagger Based API Design

28

Page 29: I Love APIs 2015: Building Predictive Apps with Lamda and MicroServices

Node.js Code

29

Page 30: I Love APIs 2015: Building Predictive Apps with Lamda and MicroServices

APIs are Everywhere

30

Hadoop

In-Memory

Insights

Node.js Node.js API BaaS

Direct Mail

Email

Web

Mobile

Outreach

Historical Events

Realtime Events

Backend

Hive

RHadoop

Node.js

Storm

Spark

Page 31: I Love APIs 2015: Building Predictive Apps with Lamda and MicroServices

Conclusion

•  Lambda architecture is a great way to combine realtime & batch processing

•  Microservices complements Lambda architecture for loosely-coupled systems

31 ©2015 Apigee. All Rights Reserved.