Recover abandoned carts from MariaDB
Start a Braze cart-recovery campaign four hours after a cart in MariaDB stops changing without a checkout. One event per cart, no tracking code.
- MariaDB
- Braze
- Lifecycle
- once per cart
The trigger
One read-only SELECT against MariaDB. Rowfire polls it for new rows, and the rule fires once per cart.
SELECT c.id AS cart_id,
c.customer_id,
c.item_count,
c.total_amount,
c.updated_at,
c.updated_at + INTERVAL 4 HOUR AS abandoned_at
FROM carts c
WHERE c.checked_out_at IS NULL
AND c.item_count > 0
AND c.customer_id IS NOT NULLAn abandoned cart is the textbook absence: the customer simply stops, and no code runs. The query defines the moment instead. Table and column names are a sketch; adapt them to your schema.
The clock is abandoned_at, four hours after the cart last changed, and the
key is cart_id, so each cart enters the campaign at most once. Carts without
a known customer are left out, since there is no one to message.
The Braze side
Bind Braze track_event with external_id set to {{ customer_id }}, an
event name like cart_abandoned, and item_count and total_amount as
properties for the message.
MariaDB is a data source like PostgreSQL and MySQL: the trigger names it, and its query runs read-only in that database’s dialect.
For orders that did go through but got stuck, see orders paid but not fulfilled.
Questions
What if the customer comes back and adds an item?
updated_at moves, so abandoned_at moves four hours past the change. If they check out, checked_out_at is set and the cart stops matching.
Why four hours?
It's an example. The delay is part of the query, so changing it is a trigger edit. A backtest over past carts shows how many would have entered the campaign at each delay.