Repositories and contributors

Repository

Carousel

Receives queued leads from CandyMuncher and prepares them for routing.

Browse the repository archive

Archive location. Dodol/Carousel. Purpose based on README.md and handlers/leadReceiverHandler.js at 7d8c364.

What the history shows

The separate CarouselMatcher repository begins with Muhammad Anwaar’s 19 December 2019 commit c9594d1. Carousel’s December revision 73c51b2 records the other side of that split by removing its Lambda matcher and scheduling code.

When a lead was missing from Carousel’s Redis state, the mobile app needed to distinguish a lead that had already been assigned. Commit 6a35371 checks CandyMuncher for that assignment before replying.

How the lead router worked

CandyMuncher sends SQS commands to Carousel. Carousel and CarouselMatcher coordinate lead queues through Redis, which also holds availability from Presence. CarouselMatcher reads policy from CandyBase and sends offers through Presence to the app. Responses return to Carousel. Carousel and CarouselMatcher send logs through a separate SQS queue to RoutingLogger, which writes to CandyBase.
Illustrative map of the archived routing flow. Open the full-size SVG.
  • Asynchronous handoffs. CandyMuncher sent start and stop commands over SQS. CarouselMatcher invoked Presence asynchronously to send an offer. See CandyMuncher/services/LeadRouter/LeadRouter.js at 789f7b2 and CarouselMatcher/app/lib/Presence.js at 6a3368f.
  • Where the services depended on each other. Carousel, CarouselMatcher, and Presence shared Redis keys for live routing and salesperson state. The matcher read eligibility and routing policy from CandyBase. On the response path, Presence waited for Carousel’s reply, and Carousel waited for CandyMuncher to confirm acceptance before clearing the lead from its queues. Direct assignments from CarouselMatcher also went to CandyMuncher. See Presence/app/lib/Carousel.js at 998c1f2, Carousel/handlers/routingResponsesHandler.js at 7d8c364, and CarouselMatcher/app/lib/CandyBase.js and app/worker.js at 6a3368f.
  • Logging on a separate queue. Carousel published offer outcomes and errors, and CarouselMatcher published direct assignments. RoutingLogger consumed these SQS messages in batches and wrote them to CandyBase. The lead and tenant IDs tied the records to the routing flow. Timestamps let it measure how long a lead waited to be offered and how long a reply took. See Carousel/handlers/lib/RoutingLogger.js at 7d8c364, CarouselMatcher/app/lib/RoutingLogger.js at 6a3368f, and RoutingLogger/handlers/newLogsHandler.js at de484b3.

How Redis coordinated routing

CandyMuncher sent routing commands to Carousel over SQS and received callbacks about lead status. Carousel and CarouselMatcher used Redis for the live routing state, alongside the salesperson connection state written by Presence. See CandyMuncher/services/LeadRouter/LeadRouter.js, Carousel/handlers/leadReceiverHandler.js at 7d8c364, and Presence/app/lib/Redis.js.

  • Wake a tenant’s worker when work arrives. Carousel stored a new lead in a Redis waiting queue scored by the time it could start routing. It then deleted the tenant’s sleep key. The worker checked that key during its backoff and could resume before its sleep timer expired. See Carousel/handlers/lib/Redis.js at 7d8c364 and CarouselMatcher/app/worker.js at 6a3368f.
  • Track the offer on both sides. Before asking Presence to deliver an offer, CarouselMatcher checked the salesperson’s live connection record in Redis and skipped people with an active offer. It recorded the new offer against both the lead and the salesperson. If the offer was rejected or timed out, Carousel cleared the salesperson’s offer marker and moved the lead back to pending, unless routing had been stopped. See CarouselMatcher/app/lib/Redis.js at 6a3368f and Carousel/handlers/routingResponsesHandler.js at 7d8c364.

Development history

  1. 2019

    From Lambda to a dedicated matcher

    1. Carousel implements lead matching

      Muhammad Anwaar committed the first implementation of Carousel with lead routing rules.

      f11653d
    2. SQS becomes the matcher trigger

      After Muhammad Anwaar configured SQS events and Reza Rosli added delayed messages for the next run, Reza made the queue the sole trigger for the Lambda matcher.

      f0140b1 7a1d2fe abad655
    3. Matching moves to CarouselMatcher

      We tried lead matching in Lambda before moving it into a separate worker. Muhammad Anwaar started the separate CarouselMatcher repository in December. Reza removed the matcher from Carousel, which kept lead intake and offer responses.

      73c51b2

Primary contributor

Reza Rosli · 195 authored commits

Added an assignment lookup when a lead was absent from the routing cache and refined when ingestion woke the matcher.

Example revisions 6a35371 (), 906f4d8 ().

When contributors were active

Authored commits per quarter through Q1 2023, oldest first. Rows are ordered by the first quarter with activity. Brighter cells show more commits. Scroll across to see later quarters.

Contributor2019 Q12019 Q22019 Q32019 Q42020 Q12020 Q22020 Q32020 Q42021 Q12021 Q22021 Q32021 Q42022 Q12022 Q22022 Q32022 Q4
Muhammad Anwaar 68 commits · 2019 Q1–2020 Q1 1 7 55 4 1 0 0 0 0 0 0 0 0 0 0 0
Reza Rosli 195 commits · 2019 Q3–2022 Q4 0 0 64 44 32 8 8 19 17 0 0 2 0 0 0 1