---
id: CreateFeedback
name: Create feedback
version: 1.0.0
badges:
  - content: Reviews
    backgroundColor: purple
    textColor: purple
summary: Creates a feedback rating for a Catalog book and returns its generated UUID.
owners:
  - catalog-experience-team
schemaPath: schema.json
operation:
  method: POST
  path: /api/v1/feedbacks
  statusCodes: ["200", "400"]
sidebar:
  badge: "POST"
---

`CreateFeedback` creates an individual [[entity|feedback]] record for a Catalog book in [[service|rating-api]] (`POST /rating/api/v1/feedbacks`), persists it to Azure Cosmos DB, publishes [[event|FeedbackCreatedIntegrationEvent]] to Kafka, and returns the generated UUIDv7 feedback identifier (`200 OK`).

## Overview

| Property                           | Value                                                                                                                                                                                   |
| :--------------------------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Bounded Context**                | Reviews                                                                                                                                                                                 |
| **Owner Service**                  | [[service\|rating-api]]                                                                                                                                                                 |
| **Protocol / Format**              | HTTP `POST`, `application/json` request and response                                                                                                                                    |
| **Gateway Endpoint**               | `POST /rating/api/v1/feedbacks` (service path `/api/v1/feedbacks`)                                                                                                                      |
| **Authentication & Authorization** | None enforced (optional Microsoft Entra ID JWT partitions per-user rate limiting when present)                                                                                          |
| **Idempotency / Concurrency**      | Not idempotent; Cosmos DB ETag optimistic concurrency on persistence                                                                                                                    |
| **Rate Limit / Caching**           | Global concurrency (`100`), per-IP fixed-window (`30 req/min`), and per-user token bucket (`30` tokens, `+20` per `10s`, queue `5`); invalidates feedback list and empty summary caches |
| **Contract Version**               | `1.0.0` (`ApiVersions.V1`)                                                                                                                                                              |

## Request & Response Contract

### Request Headers

| Name            | Type     | Required | Constraints             | Description                                                    |
| :-------------- | :------- | :------- | :---------------------- | :------------------------------------------------------------- |
| `Content-Type`  | `string` | Yes      | `application/json`      | JSON request media type                                        |
| `Authorization` | `string` | No       | `Bearer <access-token>` | Optional Entra ID JWT used to partition per-user rate limiting |

### Request Body (`application/json`)

| Name        | Type              | Required | Constraints                                          | Description                                   |
| :---------- | :---------------- | :------- | :--------------------------------------------------- | :-------------------------------------------- |
| `bookId`    | `string` (`uuid`) | Yes      | Non-empty UUID; Cosmos DB partition key              | Identifier of the Catalog book being reviewed |
| `firstName` | `string`          | Yes      | Non-empty, max `50` characters; PII-redacted in logs | Reviewer's first name                         |
| `lastName`  | `string`          | Yes      | Non-empty, max `50` characters; PII-redacted in logs | Reviewer's last name                          |
| `comment`   | `string \| null`  | No       | Max `1000` characters when provided                  | Optional written review comment               |
| `rating`    | `integer`         | Yes      | Inclusive range `0`-`5`                              | Whole-number star rating for the book         |

### Success Response (`200 OK`)

| Name       | Type              | Required | Constraints | Description                                                |
| :--------- | :---------------- | :------- | :---------- | :--------------------------------------------------------- |
| Root value | `string` (`uuid`) | Yes      | UUIDv7      | Generated unique identifier of the created feedback record |

## Behavior & Side Effects

- **Azure Cosmos DB persistence:** Persists the [[entity|feedback]] document to Cosmos DB (`ratingdb`/`feedbacks`, partitioned by `/bookId`).
- **Kafka integration event:** Publishes [[event|FeedbackCreatedIntegrationEvent]] to [[channel|bookworm.&#123;env&#125;.rating.feedback-create]] so [[service|catalog-api]] updates the book's derived rating summary.
- **Compensating rollback:** If [[service|catalog-api]] cannot find the target book and emits [[event|BookUpdatedRatingFailedIntegrationEvent]], [[service|rating-api]] deletes the orphaned feedback record and invalidates caches.
- **Cache invalidation:** Clears cached feedback list entries tagged for `bookId` and clears any cached AI summary whose `reviewCount` is `0`.
- **PII log redaction:** `firstName` and `lastName` are automatically redacted in structured logs.

## Error Responses

| Status / Code               | Condition                                                                                                                       | Client Recovery Action                                                  |
| :-------------------------- | :------------------------------------------------------------------------------------------------------------------------------ | :---------------------------------------------------------------------- |
| `400 Bad Request`           | Empty `bookId`, empty or `>50`-char `firstName`/`lastName`, `>1000`-char `comment`, `rating` outside `0`-`5`, or malformed JSON | Fix the failing fields and resubmit                                     |
| `409 Conflict`              | Cosmos DB conflict or concurrency exception                                                                                     | Refresh state or verify whether feedback already exists before retrying |
| `429 Too Many Requests`     | Rate limit quota exceeded (`Retry-After` header included)                                                                       | Wait for the `Retry-After` interval before retrying                     |
| `500 Internal Server Error` | Unexpected Cosmos DB, Kafka, or server failure (`traceId` included)                                                             | Retry with exponential backoff; inspect service logs using `traceId`    |

## Related Documentation

- [[service|rating-api]] — Service overview, Azure Cosmos DB storage, and AI summarizer.
- [[entity|feedback]] — Feedback document model.
- [[command|DeleteFeedback]] — Remove a feedback record as an administrator.
- [[event|FeedbackCreatedIntegrationEvent]] — Kafka event published on creation.
- [[query|ListFeedbacks]] — Paginate feedback records for a book.

<NodeGraph />

<SchemaViewer file="schema.json" title="Create feedback schema" maxHeight="500" search="true" />


 ## Raw Schema:schema.json

{
	"$schema": "https://json-schema.org/draft/2020-12/schema",
	"title": "CreateFeedbackCommand",
	"type": "object",
	"additionalProperties": false,
	"required": ["bookId", "firstName", "lastName", "rating"],
	"properties": {
		"bookId": {
			"type": "string",
			"format": "uuid",
			"description": "Identifier of the Catalog book being reviewed."
		},
		"firstName": {
			"type": "string",
			"minLength": 1,
			"maxLength": 50,
			"description": "First name of the reviewer."
		},
		"lastName": {
			"type": "string",
			"minLength": 1,
			"maxLength": 50,
			"description": "Last name of the reviewer."
		},
		"comment": {
			"type": ["string", "null"],
			"maxLength": 1000,
			"description": "Optional written feedback."
		},
		"rating": {
			"type": "integer",
			"minimum": 0,
			"maximum": 5,
			"description": "Rating value from 0 through 5."
		}
	}
}
