---
title: Recover a failed basket cleanup
summary: Operational procedure for investigating and recovering a failed basket deletion after checkout.
version: 1.0.0
type: runbooks
badges:
  - content: Runbook
    backgroundColor: orange
    textColor: orange
---

## Trigger / Symptom & Blast Radius

[[service|basket-api]] publishes [[event|BasketDeletedFailedIntegrationEvent]] on <ResourceLink id="bookworm.{env}.basket.delete-failed" type="channel">`bookworm.{env}.basket.delete-failed`</ResourceLink>, [[command|PlaceOrderCommand]] messages land in <ResourceLink id="bookworm.{env}.basket.dead-letter-queue" type="channel">`bookworm.{env}.basket.dead-letter-queue`</ResourceLink>, or a customer's [[entity|basket]] remains in [[container|basket-database]] after checkout. Blast radius is post-checkout basket state; always verify the downstream [[entity|order]] in [[service|order-api]] before deleting any basket.

<Admonition type="danger">
	Never delete a customer's basket until you confirm the downstream order was accepted in
	[[service|order-api]]. If the order status is ambiguous or missing, stop immediately and escalate.
</Admonition>

## Pre-Flight Check

Verify the downstream order status in [[service|order-api]] and check [[service|basket-api]] logs in `<ENV>`:

```bash
curl -sS -H "Authorization: Bearer <ADMIN_TOKEN>" "https://<GATEWAY_HOST>/ordering/api/v1/orders/<ORDER_ID>"
az containerapp logs show --name <SERVICE_NAME> --resource-group <RESOURCE_GROUP> --tail 150
```

## Quick Recovery Procedure

<Steps>
<Step title="Distinguish the two failure modes">

Inspect [[service|basket-api]] logs, [[container|basket-database]] key `basket:<CUSTOMER_ID>`, and Kafka topics (<ResourceLink id="bookworm.{env}.finance.place-order" type="channel">`bookworm.{env}.finance.place-order`</ResourceLink>, <ResourceLink id="bookworm.{env}.basket.delete-failed" type="channel">`bookworm.{env}.basket.delete-failed`</ResourceLink>, <ResourceLink id="bookworm.{env}.basket.dead-letter-queue" type="channel">`bookworm.{env}.basket.dead-letter-queue`</ResourceLink>):

**Mode A (Key already absent):** Redis was reachable, but the basket key was already gone. Finance reacts by sending [[command|DeleteBasketFailedCommand]] to [[service|order-api]], which soft-deletes the order (`404 Not Found`).

**Mode B (Transient Redis/broker exception):** Redis failed during deletion, releasing the 24-hour `OrderId` idempotency guard and routing [[command|PlaceOrderCommand]] to the DLQ while the basket remains in Redis.

</Step>
<Step title="Execute the matching recovery path">

**Mode B (Order accepted and `New`, basket still in Redis):** Restore Redis / [[service|basket-api]] health, then replay [[command|PlaceOrderCommand]] from <ResourceLink id="bookworm.{env}.basket.dead-letter-queue" type="channel">`bookworm.{env}.basket.dead-letter-queue`</ResourceLink> to <ResourceLink id="bookworm.{env}.finance.place-order" type="channel">`bookworm.{env}.finance.place-order`</ResourceLink> so [[event|BasketDeletedCompleteIntegrationEvent]] is emitted cleanly.

**Mode A (Order soft-deleted `404`) or ambiguous outcome:** Stop without modifying Redis or issuing manual order transitions, and escalate with `<ORDER_ID>`, `<CUSTOMER_ID>`, and event timestamps.

</Step>
</Steps>

## Verification

Confirm the basket is absent for the customer and [[event|BasketDeletedCompleteIntegrationEvent]] was emitted on <ResourceLink id="bookworm.{env}.basket.delete-complete" type="channel">`bookworm.{env}.basket.delete-complete`</ResourceLink>:

```bash
curl -sS -o /dev/null -w "%{http_code}\n" -H "Authorization: Bearer <CUSTOMER_TOKEN>" "https://<GATEWAY_HOST>/basket/api/v1/baskets"
```

Expected output:

```text
404
```

## Rollback / Escalation

- **Rollback:** Do not restore deleted baskets after confirmed checkout; customers can add new items anytime.
- **Escalation:** Escalate Mode A soft-deleted orders or ambiguous checkout outcomes to [[team|commerce-fulfillment-team]]; escalate Redis outages to [[team|platform-engineering-team]].

## Related documentation

- [[flow|user-checkout]] — End-to-end checkout and cleanup flow.
- [[adr|adr-005-explicit-checkout-cleanup-outcomes]] — Explicit cleanup outcome events.
