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

Practical Event Driven Architecture

Practical Event Driven Architecture

The trade-offs of using events to shape a fan-out architecture and spread data to multiple cache systems, isolating traffic-serving from data-processing pipelines.

This talk was idealized while working at heycar (https://hey.car) but presented while working at Airbnb (https://airbnb.com), that's why the slides carry the icon and information from the latter.

Avatar for Marcelo Boeira

Marcelo Boeira

November 14, 2019
Tweet

More Decks by Marcelo Boeira

Other Decks in Programming

Transcript

  1. Traditional Approach MONOLITH database application inventory customers Business Logic Hard

    to Scale Hard to Orchestrate Traffic Serving Logic Single point of failure
  2. database ? ingestion traffic serving write read ? ? TRAFFIC

    FLOW durability consistency Experimental Approach
  3. database ? ingestion traffic serving write read ? ? TRAFFIC

    FLOW performance durability consistency Experimental Approach
  4. database ? ingestion traffic serving write read ? ? TRAFFIC

    FLOW reliability performance durability consistency Experimental Approach
  5. database ? ingestion traffic serving write read ? ? TRAFFIC

    FLOW isolation reliability performance durability consistency Experimental Approach isolation reliability
  6. database ? ingestion traffic serving write read ? ? TRAFFIC

    FLOW replication isolation reliability performance durability consistency Experimental Approach replication isolation reliability
  7. database ? ingestion traffic serving write read cache ? TRAFFIC

    FLOW replication isolation reliability performance durability consistency Experimental Approach replication isolation reliability
  8. database ? ingestion traffic serving write read cache ? TRAFFIC

    FLOW replication isolation reliability performance durability consistency Experimental Approach replication isolation reliability ?
  9. database ? ingestion traffic serving write read cache ? TRAFFIC

    FLOW replication isolation reliability performance durability consistency Experimental Approach replication isolation reliability Events
  10. database ? ingestion traffic serving write read cache ? TRAFFIC

    FLOW replication isolation reliability performance durability consistency Experimental Approach replication isolation reliability Fan-out
  11. Experimental Approach DISTRIBUTED s3 bucket ingestion-service car dealerships inventory 2019/12/14/dealership-a/batch-000001.zip

    sqs WHY S3? ingestion-batch extraction-service Queue vs Stream Replay At Least Once Delivery FIFO
  12. Experimental Approach DISTRIBUTED s3 bucket ingestion-service car dealerships inventory 2019/12/14/dealership-a/batch-000001.zip

    sqs WHY S3? ingestion-batch extraction-service Queue vs Stream Replay Retry At Least Once Delivery FIFO
  13. Example Queue Consumer CODE SNIPPET loop do event = sqs.pop

    result = process(event) if result.success? event.ack else event.return end end Business Logic Remove from the queue Return to the queue { Add metrics for monitoring
  14. Experimental Approach DISTRIBUTED s3 bucket sqs extraction-service listing-service listing-db single

    consumer CSV ? consumer-a consumer-b consumer-c ordering multiple-consumers
  15. Experimental Approach DISTRIBUTED s3 bucket sqs extraction-service listing-service listing-db single

    consumer CSV consumer-a consumer-b consumer-c ordering multiple-consumers stream
  16. listing-service listing-db changes-service HTTP POST Slave Replica Write Ahead Log

    listing-stream Experimental Approach SERVICE INTERNALS
  17. listing-service listing-db changes-service HTTP POST Slave Replica Write Ahead Log

    listing-stream Experimental Approach SERVICE INTERNALS Service Unit Replication Slot CDC - change-data-capture < Unaware
  18. Experimental Approach DISTRIBUTED s3 bucket sqs extraction-service listing-service image-batch-service listing-db

    image-db changes-service changes-service listing-stream image-stream single consumer JSON payloads* s3-images CSV Pictures
  19. Example Stream Consumer CODE SNIPPET loop do record = kinesis.scan_after(position

    || horizon) result = process(record) if result.success? position = record.position end end Business Logic Update Cursor { Add metrics for monitoring
  20. Experimental Approach DISTRIBUTED listing-stream image-stream dealership-service vehicle-service pricing-service financing-service image-classification-service

    Experimental Approach dealership-db vehicle-db pricing-db financing-db image-classification-db customers front-end ?
  21. Experimental Approach DISTRIBUTED listing-stream image-stream dealership-service vehicle-service pricing-service financing-service image-classification-service

    Experimental Approach dealership-db vehicle-db pricing-db financing-db image-classification-db dealership-stream vehicle-stream pricing-stream financing-stream image-classification-stream
  22. Experimental Approach DISTRIBUTED listing-stream image-stream dealership-service vehicle-service pricing-service financing-service image-classification-service

    Experimental Approach dealership-db vehicle-db pricing-db financing-db image-classification-db dealership-stream vehicle-stream pricing-stream financing-stream image-classification-stream }
  23. Experimental Approach DISTRIBUTED listing-stream image-stream dealership-service vehicle-service pricing-service financing-service image-classification-service

    Experimental Approach dealership-db vehicle-db pricing-db financing-db image-classification-db aggregation-service dealership-stream vehicle-stream pricing-stream financing-stream image-classification-stream }
  24. Experimental Approach DISTRIBUTED Experimental Approach aggregation-service dealership-stream vehicle-stream pricing-stream financing-stream

    image-classification-stream } id listing dealership financing … a23-… JSON JSON JSON d08-… JSON JSON JSON … listing-stream
  25. Experimental Approach DISTRIBUTED Experimental Approach aggregation-service dealership-stream vehicle-stream pricing-stream financing-stream

    image-classification-stream } id listing dealership financing … a23-… JSON JSON JSON d08-… JSON JSON JSON … listing-stream
  26. Experimental Approach DISTRIBUTED Experimental Approach aggregation-service dealership-stream vehicle-stream pricing-stream financing-stream

    image-classification-stream } id listing dealership financing … a23-… JSON JSON JSON d08-… JSON JSON JSON … listing-stream
  27. Experimental Approach DISTRIBUTED Experimental Approach aggregation-service dealership-stream vehicle-stream pricing-stream financing-stream

    image-classification-stream } id listing dealership financing … a23-… JSON JSON JSON d08-… JSON JSON JSON … listing-stream Aggregate / Hydrated Document
  28. Experimental Approach FINAL OVERVIEW Experimental Approach customers inventory { }

    queue stream to stream workers core stream Ingestion Fan-out Traffic Serving aggregate-stream cache front-end ingestion-entrypoint listing-service aggregation-service
  29. Experimental Approach FINAL OVERVIEW Experimental Approach customers inventory { }

    queue stream to stream workers core stream Ingestion Fan-out Traffic Serving aggregate-stream cache front-end ingestion-entrypoint listing-service aggregation-service Isolation
  30. Experimental Approach FINAL OVERVIEW Experimental Approach customers inventory { }

    queue stream to stream workers core stream Ingestion Fan-out Traffic Serving aggregate-stream cache front-end ingestion-entrypoint listing-service aggregation-service Isolation
  31. Experimental Approach FINAL OVERVIEW Experimental Approach customers inventory { }

    queue stream to stream workers core stream Ingestion Fan-out Traffic Serving aggregate-stream cache front-end ingestion-entrypoint listing-service aggregation-service Isolation Scalable Traffic Serving
  32. Experimental Approach FINAL OVERVIEW Experimental Approach customers inventory { }

    queue stream to stream workers core stream Ingestion Fan-out Traffic Serving aggregate-stream cache front-end ingestion-entrypoint listing-service aggregation-service
  33. Experimental Approach FINAL OVERVIEW Experimental Approach customers inventory { }

    queue stream to stream workers core stream Ingestion Fan-out Traffic Serving aggregate-stream cache front-end ingestion-entrypoint listing-service aggregation-service replayable events
  34. Experimental Approach FINAL OVERVIEW Experimental Approach customers inventory { }

    queue stream to stream workers core stream Ingestion Fan-out Traffic Serving aggregate-stream cache front-end ingestion-entrypoint listing-service aggregation-service latency
  35. Experimental Approach FINAL OVERVIEW Experimental Approach customers inventory { }

    queue stream to stream workers core stream Ingestion Fan-out Traffic Serving aggregate-stream cache front-end ingestion-entrypoint listing-service aggregation-service scalable components
  36. Experimental Approach FINAL OVERVIEW Experimental Approach customers inventory { }

    queue stream to stream workers core stream Ingestion Fan-out Traffic Serving aggregate-stream cache front-end ingestion-entrypoint listing-service aggregation-service scalable components infra > code
  37. Experimental Approach FINAL OVERVIEW Experimental Approach customers inventory { }

    queue stream to stream workers core stream Ingestion Fan-out Traffic Serving aggregate-stream cache front-end ingestion-entrypoint listing-service aggregation-service bottleneck
  38. Experimental Approach FINAL OVERVIEW Experimental Approach customers inventory { }

    queue stream to stream workers core stream Ingestion Fan-out Traffic Serving aggregate-stream cache front-end ingestion-entrypoint listing-service aggregation-service bottleneck sharding
  39. Experimental Approach FINAL OVERVIEW Experimental Approach customers inventory { }

    queue stream to stream workers core stream Ingestion Fan-out Traffic Serving aggregate-stream cache front-end ingestion-entrypoint listing-service aggregation-service
  40. • CDC - Change Data Capture - Data Replication (e.g.:

    Write Ahead Log) • Queues vs Streams - Guarantees (At least once, at most once,…) - Single vs Multiple Consumers • Sharding (e.g.: parallelized processing) • Eventual Consistency (e.g.: a trade-off on performance to scale distributed systems) • Latency (e.g.: how long it takes for processing and fan-out of your data) • Stream Editing (Benthos) • Binary Serialization / Schemas - e.g.: Thrift, Protobufs… Take Home Topics INTERESTING SUBJECTS TO STUDY