erlang in the cloud - ransom · tap to talk conferencing meets messaging. on any network, or even...

42
Erlang in the Cloud Talko Service Architecture Ransom Richardson [email protected] @ransomr https://medium.com/@ransomr

Upload: others

Post on 10-Oct-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Erlang in the Cloud - Ransom · Tap to Talk Conferencing meets messaging. On any network, or even offline. Tap to Show Hi-detail photos sent instantly while talking. Mobile Team Communications

Erlang in the Cloud Talko Service Architecture

Ransom Richardson [email protected]

@ransomr https://medium.com/@ransomr

Page 2: Erlang in the Cloud - Ransom · Tap to Talk Conferencing meets messaging. On any network, or even offline. Tap to Show Hi-detail photos sent instantly while talking. Mobile Team Communications

On the Current Composition of Zero-Knowledge Proofs

2

Page 3: Erlang in the Cloud - Ransom · Tap to Talk Conferencing meets messaging. On any network, or even offline. Tap to Show Hi-detail photos sent instantly while talking. Mobile Team Communications

Erlang in the CloudIntro

• Talko • erlcloud

The Cloud is Different • Reliability • Deployment • Service State

More Erlang • Redis to Bz

Looking Forward • AWS Lambda

Questions

3

“The cloud is fundamentally different”

https://www.youtube.com/watch?v=JIQETrFC_SQ

Page 4: Erlang in the Cloud - Ransom · Tap to Talk Conferencing meets messaging. On any network, or even offline. Tap to Show Hi-detail photos sent instantly while talking. Mobile Team Communications

Always In-Sync Flag, tag, bookmark, share to reduce anxiety, increase

transparency.

Tap to TalkConferencing meets messaging. On any

network, or even offline.

Tap to Show Hi-detail photos sent

instantly while talking.

Mobile Team Communications anytime, anywhere, for the new style of work.

4

Today: Calls & ‘rich conversations’; iOS Soon: Calls, ‘rich conversations’ & messaging; iOS, Web, Android

Next: Managed deployments & administration, integration

Page 5: Erlang in the Cloud - Ransom · Tap to Talk Conferencing meets messaging. On any network, or even offline. Tap to Show Hi-detail photos sent instantly while talking. Mobile Team Communications

Talko Service• VoIP • Audio Recording • Registration • Contact matching • Group and call creation and membership • Texts, photos, tags • Notifications • User awareness • …

5

Page 6: Erlang in the Cloud - Ransom · Tap to Talk Conferencing meets messaging. On any network, or even offline. Tap to Show Hi-detail photos sent instantly while talking. Mobile Team Communications

Service Team

6

Page 7: Erlang in the Cloud - Ransom · Tap to Talk Conferencing meets messaging. On any network, or even offline. Tap to Show Hi-detail photos sent instantly while talking. Mobile Team Communications

Big Service Small TeamOptimize for Developer Productivity

7

Page 8: Erlang in the Cloud - Ransom · Tap to Talk Conferencing meets messaging. On any network, or even offline. Tap to Show Hi-detail photos sent instantly while talking. Mobile Team Communications

erlcloudhttps://github.com/gleber/erlcloud

• Partial AWS API Support • Many contributors • Implement needed APIs • Contributions welcome!

8

bwbuchanan ptrakhtman gleber kevinmontuori fogfish elbrujohalcon

Page 9: Erlang in the Cloud - Ransom · Tap to Talk Conferencing meets messaging. On any network, or even offline. Tap to Show Hi-detail photos sent instantly while talking. Mobile Team Communications

Reliability

9

Page 10: Erlang in the Cloud - Ransom · Tap to Talk Conferencing meets messaging. On any network, or even offline. Tap to Show Hi-detail photos sent instantly while talking. Mobile Team Communications

Reliability• The cloud is unreliable – expect failures • Let it Crash!

10

Erlang AWS

process instance

supervisor Auto Scale Group

Page 11: Erlang in the Cloud - Ransom · Tap to Talk Conferencing meets messaging. On any network, or even offline. Tap to Show Hi-detail photos sent instantly while talking. Mobile Team Communications

Reliability• More Than One

Instance • Different Availability

Zones • Enough extra

capacity to absorb failures

• …and load spike that is caused by failures

11

Page 12: Erlang in the Cloud - Ransom · Tap to Talk Conferencing meets messaging. On any network, or even offline. Tap to Show Hi-detail photos sent instantly while talking. Mobile Team Communications

12

DynamoDBAmazon S3

web client mobile client

Elastic LoadBalancing

Bz Servers

Session Servers

Media Servers

Page 13: Erlang in the Cloud - Ransom · Tap to Talk Conferencing meets messaging. On any network, or even offline. Tap to Show Hi-detail photos sent instantly while talking. Mobile Team Communications

Reliability

13

Talko Service

Erlang VM

erld

upstart

Auto Scaling

Page 14: Erlang in the Cloud - Ransom · Tap to Talk Conferencing meets messaging. On any network, or even offline. Tap to Show Hi-detail photos sent instantly while talking. Mobile Team Communications

Deployment

14

Page 15: Erlang in the Cloud - Ransom · Tap to Talk Conferencing meets messaging. On any network, or even offline. Tap to Show Hi-detail photos sent instantly while talking. Mobile Team Communications

Deployment

Two approaches:

1. Upgrade existing instances 2. Deploy all new instances

15

Page 16: Erlang in the Cloud - Ransom · Tap to Talk Conferencing meets messaging. On any network, or even offline. Tap to Show Hi-detail photos sent instantly while talking. Mobile Team Communications

Deployment – New Instances• Easy rollback • Need to be able to deploy quickly for

reliability • Tests reliability code path • Known instance state • Security

16

Page 17: Erlang in the Cloud - Ransom · Tap to Talk Conferencing meets messaging. On any network, or even offline. Tap to Show Hi-detail photos sent instantly while talking. Mobile Team Communications

Blue/Green Deployment• Blue service running • Deploy Green service with new code • Switch all traffic to Green • Take down Blue service

17

http://martinfowler.com/bliki/BlueGreenDeployment.html

Page 18: Erlang in the Cloud - Ransom · Tap to Talk Conferencing meets messaging. On any network, or even offline. Tap to Show Hi-detail photos sent instantly while talking. Mobile Team Communications

Talko DeploymentState would be lost on blue/green switch How do we preserve in-progress calls?

Modified approach:

• Deploy new instances • Test • Close old instances • Wait for load to move to new instances • Take down old instances

18

Page 19: Erlang in the Cloud - Ransom · Tap to Talk Conferencing meets messaging. On any network, or even offline. Tap to Show Hi-detail photos sent instantly while talking. Mobile Team Communications

19

DynamoDBAmazon S3

web client mobile client

Elastic LoadBalancing

Bz Servers

Session Servers

Media Servers

Page 20: Erlang in the Cloud - Ransom · Tap to Talk Conferencing meets messaging. On any network, or even offline. Tap to Show Hi-detail photos sent instantly while talking. Mobile Team Communications

Service State

20

Page 21: Erlang in the Cloud - Ransom · Tap to Talk Conferencing meets messaging. On any network, or even offline. Tap to Show Hi-detail photos sent instantly while talking. Mobile Team Communications

Service State

Stateless

• Event handling code only

• Easier reliability, scaling and deployment

• Limited functionality

Stateful (gen_server)

• State and message handling code

• Harder reliability, scaling and deployment

• Full functionality

21

Page 22: Erlang in the Cloud - Ransom · Tap to Talk Conferencing meets messaging. On any network, or even offline. Tap to Show Hi-detail photos sent instantly while talking. Mobile Team Communications

Talko Services are Stateful• In Progress Calls • Persistent Connections • Cross-Client Communications

How do we manage this state so we can build a reliable, scalable and deployable service?

22

Page 23: Erlang in the Cloud - Ransom · Tap to Talk Conferencing meets messaging. On any network, or even offline. Tap to Show Hi-detail photos sent instantly while talking. Mobile Team Communications

Ephemeral State• In Progress Calls • Persistent Connections • Cross-Client Communications

This state is ephemeral: • No Redundancy • Losing it results in slight (< 30s duration) user

interruption

23

Page 24: Erlang in the Cloud - Ransom · Tap to Talk Conferencing meets messaging. On any network, or even offline. Tap to Show Hi-detail photos sent instantly while talking. Mobile Team Communications

24

DynamoDBAmazon S3

web client mobile client

Elastic LoadBalancing

Bz Servers

Session Servers

Media Servers

Page 25: Erlang in the Cloud - Ransom · Tap to Talk Conferencing meets messaging. On any network, or even offline. Tap to Show Hi-detail photos sent instantly while talking. Mobile Team Communications

Ephemeral State Challenges

• Possibility of user impact • Need to detect and heal outages very quickly • Takes time for load to shift to new instances • Potential for load spikes on loss of state

25

Page 26: Erlang in the Cloud - Ransom · Tap to Talk Conferencing meets messaging. On any network, or even offline. Tap to Show Hi-detail photos sent instantly while talking. Mobile Team Communications

More ErlangRedis to Bz

26

Page 27: Erlang in the Cloud - Ransom · Tap to Talk Conferencing meets messaging. On any network, or even offline. Tap to Show Hi-detail photos sent instantly while talking. Mobile Team Communications

27

DynamoDBAmazon S3

web client mobile client

Elastic LoadBalancing

Session Servers

Media Servers

Page 28: Erlang in the Cloud - Ransom · Tap to Talk Conferencing meets messaging. On any network, or even offline. Tap to Show Hi-detail photos sent instantly while talking. Mobile Team Communications

Redis to ErlangRedis for all cross-instance communication: • Pub/Sub • Ephemeral State

28

Page 29: Erlang in the Cloud - Ransom · Tap to Talk Conferencing meets messaging. On any network, or even offline. Tap to Show Hi-detail photos sent instantly while talking. Mobile Team Communications

User Awareness

29

Page 30: Erlang in the Cloud - Ransom · Tap to Talk Conferencing meets messaging. On any network, or even offline. Tap to Show Hi-detail photos sent instantly while talking. Mobile Team Communications

30

Page 31: Erlang in the Cloud - Ransom · Tap to Talk Conferencing meets messaging. On any network, or even offline. Tap to Show Hi-detail photos sent instantly while talking. Mobile Team Communications

31

Page 32: Erlang in the Cloud - Ransom · Tap to Talk Conferencing meets messaging. On any network, or even offline. Tap to Show Hi-detail photos sent instantly while talking. Mobile Team Communications

Redis Challenges• No single server that

can run code on shared data

• Distributed Concurrent Updates to Shared State

• Complex algorithms and complex code

• Duplicated Data

32

Page 33: Erlang in the Cloud - Ransom · Tap to Talk Conferencing meets messaging. On any network, or even offline. Tap to Show Hi-detail photos sent instantly while talking. Mobile Team Communications

Bz Server• Erlang server • gen_server per

shared object (account, call)

• Much simpler code – awareness expiration is trivial

• Faster (!?!?)

33

Page 34: Erlang in the Cloud - Ransom · Tap to Talk Conferencing meets messaging. On any network, or even offline. Tap to Show Hi-detail photos sent instantly while talking. Mobile Team Communications

Looking Forward

34

Page 35: Erlang in the Cloud - Ransom · Tap to Talk Conferencing meets messaging. On any network, or even offline. Tap to Show Hi-detail photos sent instantly while talking. Mobile Team Communications

AWS LambdaJust write a function

Don’t worry about: 1. Reliability 2. Deployment 3. Machines/instances

But must be Stateless

35

Page 36: Erlang in the Cloud - Ransom · Tap to Talk Conferencing meets messaging. On any network, or even offline. Tap to Show Hi-detail photos sent instantly while talking. Mobile Team Communications

Questions

36

Page 37: Erlang in the Cloud - Ransom · Tap to Talk Conferencing meets messaging. On any network, or even offline. Tap to Show Hi-detail photos sent instantly while talking. Mobile Team Communications

Distributed ErlangWe don’t use it. Should we?

Concerns: • Clusters that cross

AZs or Regions • Speed of detecting/

healing failures • Fully interconnected

37

Page 38: Erlang in the Cloud - Ransom · Tap to Talk Conferencing meets messaging. On any network, or even offline. Tap to Show Hi-detail photos sent instantly while talking. Mobile Team Communications

Questions?Ransom Richardson [email protected]

@ransomr https://medium.com/@ransomr

Page 39: Erlang in the Cloud - Ransom · Tap to Talk Conferencing meets messaging. On any network, or even offline. Tap to Show Hi-detail photos sent instantly while talking. Mobile Team Communications

Backup Slides

39

Page 40: Erlang in the Cloud - Ransom · Tap to Talk Conferencing meets messaging. On any network, or even offline. Tap to Show Hi-detail photos sent instantly while talking. Mobile Team Communications

Choosing Erlang• https://medium.com/talko-team-talk-share-do/

we-learned-us-some-erlang-ef06bd44e3c2

● Concurrency Model ● Error Handling ● Reputation ● Domain Fit

40

Page 41: Erlang in the Cloud - Ransom · Tap to Talk Conferencing meets messaging. On any network, or even offline. Tap to Show Hi-detail photos sent instantly while talking. Mobile Team Communications

Erlang FeaturesWe Use

• OTP • Dialyzer • ETS

We Don’t Use

• Distributed Erlang • Releases/Upgrades • Mnesia

41

Page 42: Erlang in the Cloud - Ransom · Tap to Talk Conferencing meets messaging. On any network, or even offline. Tap to Show Hi-detail photos sent instantly while talking. Mobile Team Communications

Key Dependencies• erlcloud • cowboy & ranch • jsx • lager • gproc • rebar

42