Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Surrounded by Microservices

Surrounded by Microservices

The slides for the 'Surrounded by Microservices' talk , Euruko 2019, Rotterdam.

DamirSvrtan

June 21, 2019
Tweet

More Decks by DamirSvrtan

Other Decks in Programming

Transcript

  1. Various data sources ! REST API " JSON API #

    GRPC $ GraphQL % Local Database
  2. Entities module Workflows class ProductionEntity < BaseEntity attribute :id, AttrType::Strict::Integer

    attribute :title, AttrType::Strict::String attribute :logline, AttrType::Strict::String.optional end end
  3. Entities class ProductionEntity < BaseEntity attribute :id, AttrType::Strict::Integer attribute :title,

    AttrType::Strict::String attribute :logline, AttrType::Strict::String.optional end
  4. Repositories (Custom DSL) class ProductionRepo < BaseRepo entity_class ProductionEntity def

    initialize(data_source: MovieProduction) super end def find_by_id(id) wrap(data_source.find_by_id(id)) end def search_by_title(title) wrap(data_source.search_by_title(title)) end end
  5. Data Source Independent # using the default data source repo

    = ProductionRepo.new # swapping for a REST API data source repo = ProductionRepo.new(data_source: MovieProductionAPI)
  6. Interactors module Workflows class OnboardProduction include NetflixInteractor def self.call(production_id:, vertical_id:,

    repo: ProductionRepo.new) super end def call # validate inputs # is it okay to onboard a production? # cover edge cases # notify others about a production being onboarded end end end
  7. The purpose of a good architecture is to delay decisions.

    Why? Because when we delay a decision, we have more information when it comes time to make it. - Uncle Bob
  8. Testing with verified doubles describe Workflows::OnboardProduction do let(:production_id) { SecureRandom.uuid

    } let(:vertical_id) { SecureRandom.uuid } let(:response) do described_class.call(production_id: production_id, vertical_id: vertical_id, repo: repo) end describe 'when a production already exists' do let(:repo) { instance_double(Workflow::ProductionRepo, find_by_id: existing_production) } it 'the response is a failure' do expect(response).to be_a_failure end end ... end
  9. A fast and reliable spec suite Finished in 1 minute

    2.35 seconds (files took 2.93 seconds to load) 2015 examples, 0 failures