Slide 1

Slide 1 text

Building scalable applications inspired into Micro-service Architecture¬ Erik Jhordan Rey Android Tech Lead at Schibsted [email protected] @ErikJhordan_Rey github.com/erikcaffrey

Slide 2

Slide 2 text

/ SCHIBSTED MEDIA GROUP Erik Jhordan Rey Passionate about write quality code, focused to improving the profession of software development. Android Tech Lead at Segundamano

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

/ SCHIBSTED MEDIA GROUP Presence in 30 Countries MÉXICO Colombia Chile Brasil República Dominicana LATINOAMÉRICA Noruega Suecia Finlandia Bélgica Francia ESCANDINAVIA / EUROPA Portugal Alemania Polonia España Italia Irlanda Suiza Austria Hungría Rumania Bielorrusia Reino Unido Marruecos ÁFRÍCA Túnez Malasia Indonesia Singapur Vietnam Tailandia Bangladés ASIA / OCEANÍA

Slide 5

Slide 5 text

Quentin Désert Salvador Maurilio Jose Luis Cadena Carmen Salvador Jesus Antonio Mauricio Vazquez W

Slide 6

Slide 6 text

Why writing high-quality software is complicated?

Slide 7

Slide 7 text

/ SCHIBSTED MEDIA GROUP There are a lot of reasons why a software development project can fail but the most common reasons are:

Slide 8

Slide 8 text

Not Architecture

Slide 9

Slide 9 text

Architecture with smell implementations

Slide 10

Slide 10 text

Monolithic Architecture

Slide 11

Slide 11 text

/ SCHIBSTED MEDIA GROUP ● All code in a single module ● Coupled code ● Hard to maintain ● Hard to add new functionalities ● Wrong dependency Injection implementation ● Unreliable test or not tests ● Demotivated Teams

Slide 12

Slide 12 text

Let’s talk about architecture!

Slide 13

Slide 13 text

Architecture

Slide 14

Slide 14 text

/ SCHIBSTED MEDIA GROUP Architecture as a word we use when we want to talk about design but want to puff it up to make it sound important. #By Martin Fowler “In most successful software projects, the expert developers working on that project have a shared understanding of the design system design. This shared understanding is called ‘architecture.’ This understanding includes how the system is divided into components and how the components interact through interfaces. These components are usually composed of smaller components, but the architecture only includes the components and interfaces that are understood by all the developers.” #By Ralph Johnson

Slide 15

Slide 15 text

Microservice Architecture

Slide 16

Slide 16 text

/ SCHIBSTED MEDIA GROUP Way of designing software applications as suites of independently deployable services.

Slide 17

Slide 17 text

/ SCHIBSTED MEDIA GROUP Microservice Principles ● Componentization ● Organized around Business Capabilities ● Decentralized Governance ● Decentralized Data Management ● Evolutionary Design

Slide 18

Slide 18 text

Components Architecture

Slide 19

Slide 19 text

Modularized Library Architecture

Slide 20

Slide 20 text

/ SCHIBSTED MEDIA GROUP Overview

Slide 21

Slide 21 text

/ SCHIBSTED MEDIA GROUP Modularized Library Architecture ● Different android projects ● Complicated navigation between libraries ● Difficult upgrades (implies a new library release) ● Hard to maintain multiple libraries / projects ● Hard to handle library version ● Transitive dependencies

Slide 22

Slide 22 text

Modularized Feature Architecture

Slide 23

Slide 23 text

/ SCHIBSTED MEDIA GROUP Overview

Slide 24

Slide 24 text

/ SCHIBSTED MEDIA GROUP Modularized Feature Architecture ● Different android modules inside an android project ● Modules organized around business functionality ● Coupled & cyclic feature modules ● Hard to maintain cyclic dependencies ● Hard to share resources (custom views, colors, strings)

Slide 25

Slide 25 text

Modularized Layer Architecture

Slide 26

Slide 26 text

/ SCHIBSTED MEDIA GROUP Overview

Slide 27

Slide 27 text

/ SCHIBSTED MEDIA GROUP Modularized Layer Architecture ● Different android modules inside an android project ● Modules organized around layer functionality ● Coupling Modules (strong dependencies) ● Hard upgrades ● Exposed to create a bunch of git conflicts

Slide 28

Slide 28 text

How Should I modularize?

Slide 29

Slide 29 text

Inspired into Microservices Architecture

Slide 30

Slide 30 text

Modularized Feature / Layer Architecture + Clean Architecture Principles

Slide 31

Slide 31 text

/ SCHIBSTED MEDIA GROUP Overview

Slide 32

Slide 32 text

/ SCHIBSTED MEDIA GROUP Modularized Feature / Layer Architecture ● Faster build time ● Decoupled of DI library (not dagger in everywhere) ● Better structure ● Componentization ● Decentralized Data ● Maintainability ● Let's to write reliable tests

Slide 33

Slide 33 text

SMMX Android Architecture

Slide 34

Slide 34 text

Dependency Inversion Principle

Slide 35

Slide 35 text

“Your code should always depend on abstractions and not concretions”

Slide 36

Slide 36 text

/ SCHIBSTED MEDIA GROUP Hide implementation details creating layers with different responsibilities.

Slide 37

Slide 37 text

/ SCHIBSTED MEDIA GROUP hiding Implementation details, you can use test doubles ● Kotlin ● Architecture Components ○ ViewModel ○ LiveData ○ Room ● RxJava / RxAndroid ● Retrofit ● OkHttp ● Gson ● dagger 2 (dagger-android) ● JUnit ● Mockito ● Hamcrest ● MockWebServer ● Persistence Room Testing ● Barista ● Shot Testing

Slide 38

Slide 38 text

/ SCHIBSTED MEDIA GROUP

Slide 39

Slide 39 text

How it works?

Slide 40

Slide 40 text

Data Layer

Slide 41

Slide 41 text

/ SCHIBSTED MEDIA GROUP Overview

Slide 42

Slide 42 text

/ SCHIBSTED MEDIA GROUP Overview

Slide 43

Slide 43 text

/ SCHIBSTED MEDIA GROUP

Slide 44

Slide 44 text

/ SCHIBSTED MEDIA GROUP

Slide 45

Slide 45 text

Domain Layer

Slide 46

Slide 46 text

/ SCHIBSTED MEDIA GROUP Overview

Slide 47

Slide 47 text

/ SCHIBSTED MEDIA GROUP Overview

Slide 48

Slide 48 text

/ SCHIBSTED MEDIA GROUP

Slide 49

Slide 49 text

/ SCHIBSTED MEDIA GROUP

Slide 50

Slide 50 text

/ SCHIBSTED MEDIA GROUP

Slide 51

Slide 51 text

Presentation Layer

Slide 52

Slide 52 text

/ SCHIBSTED MEDIA GROUP Overview

Slide 53

Slide 53 text

/ SCHIBSTED MEDIA GROUP Overview

Slide 54

Slide 54 text

MVP -> MVVM

Slide 55

Slide 55 text

/ SCHIBSTED MEDIA GROUP ➔ ViewModel ➔ LiveData

Slide 56

Slide 56 text

/ SCHIBSTED MEDIA GROUP class LoginViewModel : ViewModel() { var liveDataLoading = MutableLiveData() // Show progress bar var liveDataSession = MutableLiveData() // Show user session var liveDataError = MutableLiveData() // Show some error

Slide 57

Slide 57 text

/ SCHIBSTED MEDIA GROUP sealed class StateData { object Loading : StateData() data class Success(var data: Any) : StateData() { inline fun responseTo() = data as T } object Complete : StateData() data class Error(val error: Throwable) : StateData() { inline fun errorTo() = error as T } }

Slide 58

Slide 58 text

/ SCHIBSTED MEDIA GROUP class LoginViewModel : ViewModel() { var stateDataLogin = MutableLiveData()

Slide 59

Slide 59 text

/ SCHIBSTED MEDIA GROUP class LoginFragment : Fragment() { private fun handleState(stateData: StateData?) { when (stateData) { is StateData.Loading -> { showProgress() } is StateData.Success -> { val session = stateData.responseTo() showUserSession(session) } is StateData.Error -> { handleError(stateData) } } }

Slide 60

Slide 60 text

● Avoid over engineering ● Maintain a clean code style ● Write clean and Solid Code ● If your code is coupled the Refactor is your friend ● Write test is our responsibility ● Understand the tools before used it ● Automatize ● Great teammate ● Be Happy!! Advices

Slide 61

Slide 61 text

01 02 https://martinfowler.com/articles/microservices.html Microservices - Martin Fowler http://files.catwell.info/misc/mirror/2003-martin-fowler-who-needs-an-architect.pdf Who needs an architect - Martin Fowler 03 Further Reading http://worrydream.com/refs/Brooks-NoSilverBullet.pdf Essence and Accident in Software Engineering - Frederick P. Brooks, Jr. 04 Service Oriented Ambiguity - Martin Fowler https://martinfowler.com/bliki/ServiceOrientedAmbiguity.html

Slide 62

Slide 62 text

Questions? Find me Erik Jhordan Rey Android Tech Lead github.com/erikcaffrey [email protected] erikcaffrey.github.io @ErikJhordan_Rey +Erik Jhordan Rey

Slide 63

Slide 63 text

Thank You 3> Droid Festival Santiago!