Building microservices web application using scala & akka

51
Building microservices web application using Scala & Akka Grokking Engineering, March 2015 Binh Nguyen - Anduin Transactions, Inc. March 21st, 2015 HCMC

Transcript of Building microservices web application using scala & akka

Page 1: Building microservices web application using scala & akka

Building microservices web application using

Scala & Akka

Grokking Engineering, March 2015Binh Nguyen - Anduin Transactions, Inc.

March 21st, 2015 HCMC

Page 2: Building microservices web application using scala & akka

Introduction: Who?

Engineer at-large with strong interest in engineering

processeses.

2

Page 3: Building microservices web application using scala & akka

Who?

August 2014 - now

Anduin Transactions

3

Page 4: Building microservices web application using scala & akka

Who?

4

PalantirTechnologies2011-2014

Page 5: Building microservices web application using scala & akka

Who?

5

Page 6: Building microservices web application using scala & akka

What?

● What is µ-services architecture? pros and cons

● Why Anduin µ-services?● How can Akka & Scala help?

6

Page 7: Building microservices web application using scala & akka

The world before microservices

7

Page 8: Building microservices web application using scala & akka

Monolithic vs microservices

8

Page 9: Building microservices web application using scala & akka

Monolithic problems

● Complexity

9

Page 10: Building microservices web application using scala & akka

Monolithic problems

● Complexity● Conway’s law => silos

10

Page 11: Building microservices web application using scala & akka

Monolithic problems

● Complexity● Conway’s law => silos● Modules development speed

11

Page 12: Building microservices web application using scala & akka

Monolithic problems

● Complexity● Conway’s law => silos● Modules development speed● Dependencies collision

12

Page 13: Building microservices web application using scala & akka

Monolithic problems

● Complexity● Conway’s law => silos● Modules development speed● Dependencies collision● Deployment

13

Page 14: Building microservices web application using scala & akka

Monolithic problems

● Complexity● Conway’s law => silos● Modules development speed● Dependencies collision● Deployment

14

Page 15: Building microservices web application using scala & akka

Can it be fixed?

15

Page 16: Building microservices web application using scala & akka

So what’s microservices?

Microservices

The term "Microservice Architecture" has sprung up over the last few years to describe a particular way of designing

software applications as suites of independently deployable services. While there is no precise

definition of this architectural style, there are certain common

characteristics around organization around business capability, automated deployment, intelligence in the

endpoints, and decentralized control of languages and data.

Martin Fowler http://martinfowler.com/articles/microservices.html

16

Page 17: Building microservices web application using scala & akka

So what’s microservices?

“complex applications are composed of small, independent processes communicating with each other using language-agnostic APIs”

Wikipedia

17

Page 18: Building microservices web application using scala & akka

Some key takeaways

● should be something one developer can fit in their head

18

Page 19: Building microservices web application using scala & akka

Some key takeaways

● Can fit in one developer head

● One developer should be able to independently produce

19

Page 20: Building microservices web application using scala & akka

Some key takeaways

● Can fit in one developer head

● One developer should be able to independently produce

● One "verb" (single concern/function, not

GET/PUT/DELETE) per microservice

20

Page 21: Building microservices web application using scala & akka

Some key takeaways

● Can fit in one developer head

● One developer should be able to independently produce

● One "verb" (single concern/function, not

GET/PUT/DELETE) per microservice

● Should be possible to deploy in a container

21

Page 22: Building microservices web application using scala & akka

Some key takeaways

● Can fit in one developer head

● One developer should be able to independently produce

● One "verb" (single concern/function, not

GET/PUT/DELETE) per microservice

● Should be possible to deploy in a container

● Can be upgraded independently

22

Page 23: Building microservices web application using scala & akka

So...what is microservices?

23

Page 24: Building microservices web application using scala & akka

Microservices challenges

24

Page 25: Building microservices web application using scala & akka

So why chasing that unicorn?

25

Page 26: Building microservices web application using scala & akka

So why chasing that unicorn?

26

Iteration speed

Page 27: Building microservices web application using scala & akka

So why chasing that unicorn?

27

Engineers autonomy

Page 28: Building microservices web application using scala & akka

28

Page 29: Building microservices web application using scala & akka

So why chasing that unicorn?

29More tools available = it’s not too bad

Page 30: Building microservices web application using scala & akka

Summary - microservices

● Microservices is challenging● ...But worths it (in my view)● Modern tools like Amazon AWS, Docker,

Deis, CoreOS, Kubenettes, Ansible, Akka, … help a lot!

30

Page 31: Building microservices web application using scala & akka

So...programming language?

31

Page 32: Building microservices web application using scala & akka

Obligatory joke on language war

32

Page 33: Building microservices web application using scala & akka

Node.js/Vert.x/Meteor

33

Page 34: Building microservices web application using scala & akka

Go

● Readability over everything else● Battery included● Google● Easy to pick up● A bit of niche feel (more system oriented)● No Type safety● Some problems with cross OSs compiling

34

Page 35: Building microservices web application using scala & akka

OK, more serious choice: Java

35

Page 36: Building microservices web application using scala & akka

OK, more serious choice: Java

36

Page 37: Building microservices web application using scala & akka

Java: Multithreaded programming

37

In Theory

Page 38: Building microservices web application using scala & akka

Java: Multithreaded programming

38

In Practice

Page 39: Building microservices web application using scala & akka

Java: Lack of functional and Immutability

39

Page 40: Building microservices web application using scala & akka

ClojureMy personal favorite language

● Simple but no simpler● Lisp● Rich Hickey & the likes● ClojureScript● Weak libraries● Dynamic typing

40

Page 41: Building microservices web application using scala & akka

Scala: Very complicated

41

Page 42: Building microservices web application using scala & akka

Scala: Long time to master

42

Page 43: Building microservices web application using scala & akka

Akka = Actor model

● One of the biggest reason for choosing Scala!

43

Concurrent and distributed programming done right

Page 44: Building microservices web application using scala & akka

Akka’s “cool kids” club!

● Apache Spark● Apache Kafka● Apache Samza● Spray● ….

44

Page 45: Building microservices web application using scala & akka

Akka Remote Actor and Clustering

● Location transparency● Distributed by default (beware: Fallacies of

distributed computing)

45

Page 46: Building microservices web application using scala & akka

Akka Persistence

● Actor state snapshot for easier recovery● Event sourcing

46

Page 47: Building microservices web application using scala & akka

Akka reactive streaming

Data flow at the same speed as the slowest link to prevent buffer blows up.

47

Page 48: Building microservices web application using scala & akka

Akka: built for modern web

● Akka http 2.0● Akka websocket● Akka webRTC

48

Page 49: Building microservices web application using scala & akka

Conclusion: Scala & Akka

49

Page 50: Building microservices web application using scala & akka

50

Page 51: Building microservices web application using scala & akka

51