Building microservices web application using scala & akka

Post on 16-Jul-2015

785 views 2 download

Transcript of 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

Introduction: Who?

Engineer at-large with strong interest in engineering

processeses.

2

Who?

August 2014 - now

Anduin Transactions

3

Who?

4

PalantirTechnologies2011-2014

Who?

5

What?

● What is µ-services architecture? pros and cons

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

6

The world before microservices

7

Monolithic vs microservices

8

Monolithic problems

● Complexity

9

Monolithic problems

● Complexity● Conway’s law => silos

10

Monolithic problems

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

11

Monolithic problems

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

12

Monolithic problems

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

13

Monolithic problems

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

14

Can it be fixed?

15

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

So what’s microservices?

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

Wikipedia

17

Some key takeaways

● should be something one developer can fit in their head

18

Some key takeaways

● Can fit in one developer head

● One developer should be able to independently produce

19

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

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

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

So...what is microservices?

23

Microservices challenges

24

So why chasing that unicorn?

25

So why chasing that unicorn?

26

Iteration speed

So why chasing that unicorn?

27

Engineers autonomy

28

So why chasing that unicorn?

29More tools available = it’s not too bad

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

So...programming language?

31

Obligatory joke on language war

32

Node.js/Vert.x/Meteor

33

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

OK, more serious choice: Java

35

OK, more serious choice: Java

36

Java: Multithreaded programming

37

In Theory

Java: Multithreaded programming

38

In Practice

Java: Lack of functional and Immutability

39

ClojureMy personal favorite language

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

40

Scala: Very complicated

41

Scala: Long time to master

42

Akka = Actor model

● One of the biggest reason for choosing Scala!

43

Concurrent and distributed programming done right

Akka’s “cool kids” club!

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

44

Akka Remote Actor and Clustering

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

distributed computing)

45

Akka Persistence

● Actor state snapshot for easier recovery● Event sourcing

46

Akka reactive streaming

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

47

Akka: built for modern web

● Akka http 2.0● Akka websocket● Akka webRTC

48

Conclusion: Scala & Akka

49

50

51