Mock CTO interview: syncing stock and orders with an ERP using Celery

Mock CTO Interview November 13, 2026 python

You: "With Celery tasks.

python
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
# ======================================================================
# Q: CTO: "How did the synchronization with the ERP work?"
#
# You: "With Celery tasks. Pull for stock and prices every few minutes with
# Celery beat, push for orders via transaction.on_commit. The tasks were
# idempotent with a unique external_id, had retries with exponential backoff,
# and raised an alert when they failed repeatedly. A nightly reconciliation job
# found discrepancies."
# ======================================================================

@shared_task
def pull_stock_from_erp():
    rows = erp.fetch_stock(changed_since=cache.get('erp_stock_cursor'))
    by_sku = {r.sku: r.qty for r in rows}
    products = list(Product.objects.filter(sku__in=by_sku))
    for p in products:
        p.stock = by_sku[p.sku]
    Product.objects.bulk_update(products, ['stock'], batch_size=1000)
    cache.set('erp_stock_cursor', rows.cursor, None)