Building scalable applications inspired into Micro-service Architecture

Building scalable applications inspired into Micro-service Architecture

The term "Microservice Architecture" has been used in recent years to describe a particular way of designing software applications as suites of independent services, allowing architectures to be refactored or replaced in smaller pieces as the business grows, instead to replace or refactor a complete application. We learn to encapsulate parts of an application in autonomous services that can be designed, developed, tested and implemented individually with little or no dependency on other components or services of an application.

9f523401a845a29c93ff73cde4c3db2b?s=128

Erik Jhordan Rey

October 20, 2018
Tweet

Transcript

  1. Building scalable applications inspired into Micro-service Architecture¬ Erik Jhordan Rey

    Android Tech Lead at Schibsted erik.gonzalez@schibsted.com @ErikJhordan_Rey github.com/erikcaffrey
  2. / SCHIBSTED MEDIA GROUP Erik Jhordan Rey Passionate about write

    quality code, focused to improving the profession of software development. Android Tech Lead at Segundamano
  3. None
  4. / 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
  5. Quentin Désert Salvador Maurilio Jose Luis Cadena Carmen Salvador Jesus

    Antonio Mauricio Vazquez W
  6. Why writing high-quality software is complicated?

  7. / SCHIBSTED MEDIA GROUP There are a lot of reasons

    why a software development project can fail but the most common reasons are:
  8. Not Architecture

  9. Architecture with smell implementations

  10. Monolithic Architecture

  11. / 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
  12. Let’s talk about architecture!

  13. Architecture

  14. / 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
  15. Microservice Architecture

  16. / SCHIBSTED MEDIA GROUP Way of designing software applications as

    suites of independently deployable services.
  17. / SCHIBSTED MEDIA GROUP Microservice Principles • Componentization • Organized

    around Business Capabilities • Decentralized Governance • Decentralized Data Management • Evolutionary Design
  18. Components Architecture

  19. Modularized Library Architecture

  20. / SCHIBSTED MEDIA GROUP Overview

  21. / 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
  22. Modularized Feature Architecture

  23. / SCHIBSTED MEDIA GROUP Overview

  24. / 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)
  25. Modularized Layer Architecture

  26. / SCHIBSTED MEDIA GROUP Overview

  27. / 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
  28. How Should I modularize?

  29. Inspired into Microservices Architecture

  30. Modularized Feature / Layer Architecture + Clean Architecture Principles

  31. / SCHIBSTED MEDIA GROUP Overview

  32. / 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
  33. SMMX Android Architecture

  34. Dependency Inversion Principle

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

  36. / SCHIBSTED MEDIA GROUP Hide implementation details creating layers with

    different responsibilities.
  37. / 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
  38. / SCHIBSTED MEDIA GROUP

  39. How it works?

  40. Data Layer

  41. / SCHIBSTED MEDIA GROUP Overview

  42. / SCHIBSTED MEDIA GROUP Overview

  43. / SCHIBSTED MEDIA GROUP

  44. / SCHIBSTED MEDIA GROUP

  45. Domain Layer

  46. / SCHIBSTED MEDIA GROUP Overview

  47. / SCHIBSTED MEDIA GROUP Overview

  48. / SCHIBSTED MEDIA GROUP

  49. / SCHIBSTED MEDIA GROUP

  50. / SCHIBSTED MEDIA GROUP

  51. Presentation Layer

  52. / SCHIBSTED MEDIA GROUP Overview

  53. / SCHIBSTED MEDIA GROUP Overview

  54. MVP -> MVVM

  55. / SCHIBSTED MEDIA GROUP ➔ ViewModel ➔ LiveData

  56. / SCHIBSTED MEDIA GROUP class LoginViewModel : ViewModel() { var

    liveDataLoading = MutableLiveData<Any>() // Show progress bar var liveDataSession = MutableLiveData<Session>() // Show user session var liveDataError = MutableLiveData<SessionError>() // Show some error
  57. / SCHIBSTED MEDIA GROUP sealed class StateData { object Loading

    : StateData() data class Success(var data: Any) : StateData() { inline fun <reified T> responseTo() = data as T } object Complete : StateData() data class Error(val error: Throwable) : StateData() { inline fun <reified T> errorTo() = error as T } }
  58. / SCHIBSTED MEDIA GROUP class LoginViewModel : ViewModel() { var

    stateDataLogin = MutableLiveData<StateData>()
  59. / SCHIBSTED MEDIA GROUP class LoginFragment : Fragment() { private

    fun handleState(stateData: StateData?) { when (stateData) { is StateData.Loading -> { showProgress() } is StateData.Success -> { val session = stateData.responseTo<Session>() showUserSession(session) } is StateData.Error -> { handleError(stateData) } } }
  60. • 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
  61. 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
  62. Questions? Find me Erik Jhordan Rey Android Tech Lead github.com/erikcaffrey

    erik.gonzalez@schibsted.com erikcaffrey.github.io @ErikJhordan_Rey +Erik Jhordan Rey
  63. Thank You 3> Droid Festival Santiago!