Post on 16-Apr-2017
1
Building predictive apps with λ & μ-services architecture #Alan Ho @karlunho
Director of Product
Context is King
2
Technology Choices Today
3
Datawarehouse RDBMS J2EE AppServer
Lambda Architecture
4
What is Context ?
5
Historical #Events#
Recent#Events#
Now#
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
Web
Mobile
Outreach
Req / Res Processing
Historical Events
Recent Events
Netflix
7
• Offline = Batch Layer
• Nearline = Speed Layer
• Online = Serving Layer
Batch Layer (Offline) • Singular Value
Decomposition
• Batch like operations
• High algorithm complexity
• Results Flow into Cassandra
Speed Layer (Near Line)
10
• Medium request/response
• Medium data
• Medium algorithm complexity
• Intermediate caching, incremental learning algos
Serving layer (Online)
• Fast request/response, performance is key – high availability/SLA
• Fallback mechanism to Nearline/Offline operations
• Low algorithm complexity
Final Thoughts: • Very complete system
• Very custom and high performance
• Lots of specialized systems for specialized tasks
• Not practical for most enterprises
Microservices & LambdaArchitecture
13
App Explosion
14
How can I embed context-awareness in all customer experiences?
Micro-services
15
Micro-services Best Practice
16
Isolation REST API
HTTP://<Resource>/
Isolation at all tiers
17
Batch Storage
Near RT Storage
Batch Processing
(MR)
Near RealTime
Processing
Query DB
APIs
Direct Mail
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#
API at all tiers
18
Batch Layer# Serving Layer#
Speed Layer#
Direct Mail
Web
Mobile
Outreach
/Scores#
/Counts#
/Recommendations#
Historical Events
Recent Events
Real-time Scoring for Recommendations
19
Recommendations Example
20
Real-time Scoring Architecture
21
Hadoop
In-Memory
Insights (GRASP)
Node.js
Node.js API BaaS
(APIs)
Direct Mail
Web
Mobile
Outreach
(Batch Scores)
(Activities / Counters)
(Query)
Historical Events
Realtime Events
(Context)
Backend
(Mashup)
3 4
5
1
2 6
Node.js
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
23
R Code#
24
Scored Export to Serving Layer#
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
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:#
Microservices Layer
• API Layer (Swagger)
• Context Injection
• Service Orchestration
• Fallback logic
27
Node.js Node.js API BaaS
Direct Mail
Web
Mobile
Outreach
(Context)
Backend
Swagger Based API Design
28
Node.js Code
29
APIs are Everywhere
30
Hadoop
In-Memory
Insights
Node.js Node.js API BaaS
Direct Mail
Web
Mobile
Outreach
Historical Events
Realtime Events
Backend
Hive
RHadoop
Node.js
Storm
Spark
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.