com-example-service-InventoryService · git:20260914.8205252 · 2026-09-14 · sha256 185d1fcb4208f4e6

com-example-service-InventoryService git:20260914.8205252A

Immutable. This exact content never changes and is served at /api/v1/blob/185d1fcb4208f4e6.

---
description: "AI rules for com.example.service.InventoryService"
globs: **/InventoryService.java
alwaysApply: false
---

<!-- VIBETAGS-START -->
# Rules for InventoryService

## Context & Focus
- **Focus**: Maintain inventory consistency across concurrent requests. All stock updates must be atomic.
- **Avoid**: Non-atomic read-modify-write sequences, unsynchronized shared state

### Rules for field customerId
- **Rule**: Never log or expose runtime values of this element.
- **Reason**: Customer identifiers linked to purchase history — PII under GDPR

### Rules for method releaseReservation
- **Sensitivity**: High
- **Note**: Must be called as the exact inverse of reserveStock. Pair changes to both methods together.

### Rules for method reserveStock
- **Sensitivity**: Critical
- **Note**: Reservation logic handles concurrent requests via optimistic locking. Took 18 months to get right under high load — do not refactor without running the full concurrency test suite.

## Performance Constraints
- **Rule**: Optimal complexity required. O(n^2) is forbidden on hot paths.

### Rules for method bulkRestock
- **Constraint**: Must process 10 000 SKU updates/second. O(n) acceptable; O(n log n) only if unavoidable; O(n²) is forbidden.

### Rules for method getAvailableStock
- **Constraint**: O(1) lookup required. Must complete in <2ms p99. No database calls permitted; reads from in-memory cache only.

### Rules for method sendLowStockAlert
- **Flag**: 'inventory.push-alerts.enabled' (default: false)
- **Rule**: This code is gated behind a feature flag. Preserve the flag check. Never assume the flag is always active.
<!-- VIBETAGS-END -->