Algorithm · Instacart · Medium
Naive scheduled job – not idempotent def send_due_24h_notifications(conn): due_time = datetime.now() + timedelta(hours=24) with conn.cursor() as cur: cur.execute( "SELECT * FROM loan WHERE due_date = %s AND returned = false", (due_time,) ) for row in cur.fetchall(): insert_notification(conn, row['patron_id'], 'due_24h', row['loan_id']) def insert_notification(conn, patron_id, type_, loan_id): INSERT INTO notification ... Time & Space Complexity Time complexity: O(L) per run,…
Checking your access…