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

Using Elixir to fight Covid-19

Eric Saxby
March 10, 2021
140

Using Elixir to fight Covid-19

Presented at CodeBEAM V America on March 10, 2021.

Eric Saxby

March 10, 2021
Tweet

Transcript

  1. Timeline of this talk March Let’s help with Covid! (I

    wish this was Elixir) April/May Let’s help New York contact tracing (could we do this in Elixir?) June/July Let’s rewrite this with Broadway
  2. {{PD-1996}} Gustav Moreau's Diomede devoured by his horses (1865) -

    Track hospital usage & needs - Allow supply chain to route to tomorrow’s needs - Ruby on Rails - Heroku PPE resource status
  3. @jasondeblooisphotography - March 2020 : CHAOS - Large companies also

    solving this problem - Project purposefully shut down Retrospective
  4. Caravaggio's Cardsharps (1594) {{PD-1996}} - Generic platform - Busy with

    user workflows - Unable to add integrations Contact Tracing
  5. @jasondeblooisphotography - Elixir v Node v Ruby - all allow

    rapid development - Elixir turned out simpler resilient solutions Retrospective
  6. Deeper look @ data pipeline - State database - HL7

    aggregator - Each lab (possibly each location) creates its own integration - Required fields, with minimal/no validations - No built in Master Patient Index
  7. Master Patient Index - Unique ID for each person in

    the public health system - Deduplication - Cross-reference - Each state** runs their own MPI ** or they might not
  8. State database Somebody gets the file They give it to

    this person Who asks someone to “enrich” the data So they can get an MPI (hours later) Then they give it to this person Who undoes some of the previous steps?? Then gives it to us? So we can put the data in the Contact Tracing system every 30m literally forever 5s ?? N hours ??
  9. With “post-processing” that undoes any deduplication from the MPI Only

    7% successful MPI might not be unique Changes delimiter, without escaping data
  10. Consequences Jacques-Louis David's Sorrow (1773) {{PD-1996}} - Massive delays, for

    little benefit - Multiple calls to the same people - Overloaded workers - Low trust
  11. 555 555 1234 000 000 0000 1 {wait, is that

    a hospital?} {yeah, that’s definitely a hospital} 555 1234 Phone numbers
  12. 123 Main St 123 Mani St {wait, is this a

    hospital?} {yeah, that’s definitely a hospital} Addresses
  13. Names Leonardo / da / Vinci Leonardo da / /

    Vinci Leonardo / / Vinci Leo / / Vinci Loenardo / / Vinci
  14. Leonardo / da / Vinci / M Leonardo da /

    / Vinci / M Leonardo / / Vinci / M Leo / / Vinci / M Leonardo / da / Vinci / F Gender
  15. …with no unique constraints… …because they come from lab systems…

    …that sometimes recycle ids every month… …with no guarantee that different labs won’t use the same id… “Unique” identifiers
  16. Can we be an MPI? Vasily Polenov's Left hand with

    the index finger (c1885) {{PD-1996}}
  17. - Addresses - nope - Name and birth date? -

    Gender? - nope - Phone numbers? - nope - Accession #s - nope Vasily Polenov's Left hand with the index finger (c1885) {{PD-1996}}
  18. Eugène Delacroix's Hamlet and Horatio in the Cemetary (1839) {{PD-1996}}

    Lets talk to people! - Data is unreliable - Duplication is terrible - Full time positions finding duplicates
  19. Eugène Delacroix's Hamlet and Horatio in the Cemetary (1839) {{PD-1996}}

    Insights - Manual correction is fine* - * if quantity is low enough - Problem is duplicate phone calls
  20. Odilon Redon's Icarus (c1890) {{PD-1996}} Insights - There was no

    MPI - “Good enough” would be much better than what’s there
  21. Odilon Redon's Icarus (c1890) {{PD-1996}} Giorgio / G / Vasari

    / M / 1511 / ABC123 Giorgio G / / Vasari / M / 1511 / ABC123 Giorgio / G / Vasari / F / 1511 / ABC123 Gorgio / / Vasari / M / 1511 / ABC124 Giorgio / / Vasari / M / 1151 / ABC125 Giorgio / Geo / Vasari / F / 1511 / ABC126 Giorgio / G / Vasari / M / 1511 / CDE123
  22. Odilon Redon's Icarus (c1890) {{PD-1996}} Giorgio / G / Vasari

    / M / 1511 / ABC123 Giorgio G / / Vasari / M / 1511 / ABC123 Giorgio / G / Vasari / F / 1511 / ABC123 Gorgio / / Vasari / M / 1511 / ABC124 Giorgio / / Vasari / M / 1151 / ABC125 Giorgio / Geo / Vasari / F / 1511 / ABC126 Giorgio / G / Vasari / M / 1511 / CDE123
  23. A brief history of streams - Enum - Jan 6,

    2012 - “Start working on Enum protocol” - Stream - June 30, 2013 - “Add streams” - GenStage - Aug 26, 2015 - initial commit - Flow - Jan 17, 2017 - initial commit - Broadway - Feb 25, 2019 - Announcing Broadway
  24. Melchior d'Hondecoeter's The Menagerie (1690) {{PD-1996}} File Row Processor Row

    Batcher New Person Processor Lab Result Processor Lab Result Batcher ContactTracing Adapter Processor Batcher
  25. File Row Processor Batcher New Person Processor Lab Result Processor

    Lab Result Batcher ContactTracing Adapter Processor Batcher
  26. - Old pipeline - now 3-8hrs - Broadway - 15m

    - +SP 200:200 - 10m - ETS cache - 25s 500k+ database queries
  27. handle_demand/2 handle_demand — county 1, page 1 - extra records

    set into a buffer on state handle_demand — read from buffer handle_demand — next page, extras on buffer - if no next page, increment county handle_demand — county 2, page 1 …etc
  28. Dispatcher Dispatcher Dispatcher Dispatcher Dispatcher • Consumers demand work from

    their dispatcher • Dispatchers demand work from producers • If the producer does not fill demand, the dispatcher may wait for more events to arrive When there is more demand than data, producers must track unmet demand
  29. handle_demand/2 - handle_demand — county 1, page 1 - extra

    records set into a buffer on state - handle_demand — read from buffer - handle_demand — next page, extras on buffer - if no next page, increment county - county 2, page 1 - …etc Last page may not fulfill demand
  30. - HTTP(S) is unreliable - Don’t trust system uptime -

    Broadway does not come with retries - though it may be implemented in a producer
  31. - Background job runner - Built-in retry - Oban Web

    - paid license - Quick to set up - Uses PostgreSQL for queues Hans Gude's Oban Bay (1889) {{PD-1996}}
  32. Melchior d'Hondecoeter's The Menagerie (1690) {{PD-1996}} File Producer Row Processor

    Row Batcher Unprocessed TestResults Producer People/Case Processor Cases in CommCare Push to Oban Processor New/Updated Cases Producer Test Results (unique rows in files) People + Cases Oban Cases Updated in CT Producer Case Processor People + Cases Cases updated in CommCare
  33. - Broadway is awesome - Its limits are fine -

    In the future, maybe just GenStage - Event sourcing - Our domain schemas were fine - Maybe eventstore/Kafka next time - OpenTelemetry - Endemic problems in health care - Need more individuals able to predict consequences