---
id: DeleteBasketFailedCommand
name: Handle basket deletion failed
version: 1.0.0
badges:
  - content: Order Lifecycle
    backgroundColor: blue
    textColor: blue
summary: |
  Reports Finance's failed basket-cleanup outcome so Order API can
  soft-delete the affected Order.
owners:
  - commerce-fulfillment-team
schemaPath: schema.json
---

`DeleteBasketFailedCommand` (v1.0.0) is an asynchronous Kafka integration command published by [[service|order-orchestration]] instructing [[service|order-api]] to soft-delete an order whose post-checkout basket cleanup failed or whose orchestration rolled back. [[service|order-api]] marks the order deleted without transitioning its business status to `Cancelled`.

## Overview

| Property                             | Value                                                                                |
| :----------------------------------- | :----------------------------------------------------------------------------------- |
| **Bounded Context**                  | Ordering                                                                             |
| **Producer**                         | [[service\|order-orchestration]]                                                     |
| **Consumer(s)**                      | [[service\|order-api]]                                                               |
| **Protocol / Format**                | Kafka + CloudEvents JSON (camelCase payload)                                         |
| **Channel / Topic**                  | [[channel\|bookworm.&#123;env&#125;.finance.delete-basket-failed]]                   |
| **Dead-Letter Channel**              | [[channel\|bookworm.&#123;env&#125;.ordering.dead-letter-queue]]                     |
| **Partition Key**                    | `OrderId`                                                                            |
| **Delivery / Idempotency Guarantee** | At-least-once delivery; consumed with Redis-backed 24-hour idempotency keyed by `id` |

:::note
`DeleteBasketFailedCommand` is distinct from [[event|BasketDeletedFailedIntegrationEvent]]. [[service|basket-api]] publishes `BasketDeletedFailedIntegrationEvent` to [[service|order-orchestration]], which then publishes `DeleteBasketFailedCommand` to [[service|order-api]].
:::

## Payload Fields & Envelope

### Command Payload

| Name           | Type                   | Required | Constraints                     | Description                                                     |
| :------------- | :--------------------- | :------- | :------------------------------ | :-------------------------------------------------------------- |
| `id`           | `string` (`uuid`)      | Yes      | UUIDv7                          | Unique message identifier used as the Redis idempotency key     |
| `creationDate` | `string` (`date-time`) | Yes      | ISO 8601 UTC timestamp          | UTC timestamp when the command was created                      |
| `basketId`     | `string` (`uuid`)      | Yes      | Valid UUID                      | Identifier of the basket whose cleanup failed                   |
| `email`        | `string \| null`       | Yes      | Nullable email string           | Customer email address when available (`null` when unavailable) |
| `orderId`      | `string` (`uuid`)      | Yes      | Valid UUID; Kafka partition key | Identifier of the affected order to soft-delete                 |
| `totalMoney`   | `number`               | Yes      | Non-negative monetary amount    | Total purchase amount associated with the order                 |

## Delivery Guarantees & Error Handling

| Condition                               | System Behavior                                                                | Recovery / Compensation                                                                      |
| :-------------------------------------- | :----------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------- |
| Duplicate delivery within 24 hours      | Consumer skips reprocessing via Redis-backed 24-hour idempotency keyed by `id` | Safe at-least-once delivery                                                                  |
| Order not found or already soft-deleted | Consumer exits cleanly without error                                           | Naturally idempotent no-op                                                                   |
| Transient database or broker failure    | Retried with cooldown (`50ms`, `250ms`, `1s` with full jitter)                 | Exhausted messages route to [[channel\|bookworm.&#123;env&#125;.ordering.dead-letter-queue]] |

## Related Documentation

- [[service|order-api]] — Consuming service, soft-delete filter, and Kafka setup.
- [[service|order-orchestration]] — Producing orchestration service.
- [[channel|bookworm.&#123;env&#125;.finance.delete-basket-failed]] — Kafka topic specification.
- [[channel|bookworm.&#123;env&#125;.ordering.dead-letter-queue]] — Dead-letter queue for failed Ordering consumers.
- [[command|DeleteBasketCompleteCommand]] — Companion command for successful basket cleanup.
- [[event|BasketDeletedFailedIntegrationEvent]] — Upstream failure event from [[service|basket-api]].

<NodeGraph />

<SchemaViewer
	file="schema.json"
	title="Handle basket deletion failed schema"
	maxHeight="500"
	search="true"
/>


 ## Raw Schema:schema.json

{
	"$schema": "https://json-schema.org/draft/2020-12/schema",
	"title": "DeleteBasketFailedCommand",
	"type": "object",
	"additionalProperties": false,
	"required": ["id", "creationDate", "basketId", "email", "orderId", "totalMoney"],
	"properties": {
		"id": {
			"type": "string",
			"format": "uuid",
			"description": "Unique identifier assigned to the integration message."
		},
		"creationDate": {
			"type": "string",
			"format": "date-time",
			"description": "UTC timestamp when the integration message was created."
		},
		"basketId": {
			"type": "string",
			"format": "uuid",
			"description": "Identifier of the basket whose cleanup failed."
		},
		"email": {
			"type": ["string", "null"],
			"format": "email",
			"description": "Customer email, when available."
		},
		"orderId": {
			"type": "string",
			"format": "uuid",
			"description": "Identifier of the affected Order."
		},
		"totalMoney": {
			"type": "number",
			"format": "double",
			"description": "Total purchase amount associated with the Order."
		}
	}
}
