Our referral program rewards the sponsor 16 days after the referee's payment. A cron takes that decision every morning. The referee's app has to be still active, its invoice paid without incident and without a credit note, and a few other checks have to pass. If a condition fails, the cron tries again the next day, and gives up 46 days after the payment.
Some context. I run backend engineering at GoodBarber , an app platform, and the referral program went live on October 23. Before launch, the review found three bugs in that decision. They have the same root. A check that runs 16 days later reads the database as it is now, and the database had changed in between.
Which date is "the payment"?
The first version counted the 16 days from the invoice date. An invoice can be created, go unpaid, and be settled later. When we regularize an unpaid invoice, only its settlement date changes.…