Skip to content

Commit 1dc8009

Browse files
committed
remove error handling redundant language
1 parent adb17b6 commit 1dc8009

15 files changed

Lines changed: 0 additions & 154 deletions

File tree

common/src/main/java/com/example/common/enums/SagaStatus.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,5 @@
11
package com.example.common.enums;
22

3-
/**
4-
* Lifecycle states for a Saga workflow instance.
5-
*
6-
* <p>State transitions:
7-
*
8-
* <p>STARTED → RUNNING → COMPLETED ↘ FAILED (permanent business failure — no retry) ↘ PENDING_RETRY
9-
* (transient failure — will retry) ↘ PERMANENTLY_FAILED (max retries exhausted)
10-
*
11-
* <p>KEY DISTINCTION: FAILED = business rule prevented completion (out of stock, card declined) No
12-
* retry — retrying won't help PERMANENTLY_FAILED = transient failure exhausted all retries Needs
13-
* manual intervention or customer action PENDING_RETRY = transient failure, retry scheduled at
14-
* next_retry_at
15-
*/
163
public enum SagaStatus {
174
STARTED,
185
RUNNING,

common/src/main/java/com/example/common/exceptions/DuplicateOrderException.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,6 @@
22

33
import java.util.UUID;
44

5-
/**
6-
* Thrown when an order already exists for this saga in a conflicting state.
7-
*
8-
* <p>NOTE: This is different from idempotency. Idempotency means: "I already did this work
9-
* successfully, here's the result." DuplicateOrderException means: "An order exists for this saga
10-
* but something is wrong."
11-
*
12-
* <p>FAILURE SCENARIO: "Order creation fails (duplicate order)"
13-
*/
145
public class DuplicateOrderException extends PermanentWorkerException {
156

167
public DuplicateOrderException(UUID sagaId) {

common/src/main/java/com/example/common/exceptions/InsufficientStockException.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,5 @@
11
package com.example.common.exceptions;
22

3-
/**
4-
* Thrown when requested quantity exceeds available stock.
5-
*
6-
* <p>PERMANENT failure — retrying won't restock the warehouse.
7-
*
8-
* <p>FAILURE SCENARIO: "Inventory check fails (out of stock)" FAILURE SCENARIO: "Inventory
9-
* partially available (some items in stock, some not)"
10-
*
11-
* <p>The message should identify which product(s) failed and why. Example: "Insufficient stock for
12-
* prod_1: requested=5, available=2"
13-
*/
143
public class InsufficientStockException extends PermanentWorkerException {
154

165
public InsufficientStockException(String productId, int requested, int available) {

common/src/main/java/com/example/common/exceptions/PaymentDeclinedException.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
11
package com.example.common.exceptions;
22

3-
/**
4-
* Thrown when a payment is declined by the payment provider.
5-
*
6-
* <p>PERMANENT failure — retrying a declined card won't approve it. The customer needs to use a
7-
* different payment method.
8-
*
9-
* <p>FAILURE SCENARIO: "Payment declined (insufficient funds)"
10-
*
11-
* <p>Simulate by using token: "tok_declined"
12-
*/
133
public class PaymentDeclinedException extends PermanentWorkerException {
144

155
public PaymentDeclinedException(String token) {

common/src/main/java/com/example/common/exceptions/PermanentWorkerException.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
package com.example.common.exceptions;
22

3-
/**
4-
* Permanent failure — retrying will NOT help.
5-
*
6-
* <p>When the orchestrator catches this, it marks the saga FAILED immediately. No retry is
7-
* scheduled. The customer needs to take action.
8-
*
9-
* <p>Subclasses: InsufficientStockException, PaymentDeclinedException, DuplicateOrderException
10-
*/
113
public class PermanentWorkerException extends WorkerException {
124

135
public PermanentWorkerException(String message) {

common/src/main/java/com/example/common/exceptions/TransientWorkerException.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
package com.example.common.exceptions;
22

3-
/**
4-
* Transient failure — retrying MAY help.
5-
*
6-
* <p>When the orchestrator catches this, it schedules a retry with exponential backoff. If max
7-
* retries are exhausted, the saga moves to PERMANENTLY_FAILED.
8-
*
9-
* <p>Use this for: DB timeouts, network blips, service temporarily unavailable, any infrastructure
10-
* failure that is expected to resolve on its own.
11-
*/
123
public class TransientWorkerException extends WorkerException {
134

145
public TransientWorkerException(String message) {

inventory-worker/src/main/java/com/example/inventory/domain/InventoryItem.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,6 @@
55
import lombok.NoArgsConstructor;
66
import lombok.Setter;
77

8-
/**
9-
* Represents stock levels for a single product.
10-
*
11-
* <p>INVARIANT: available_qty + reserved_qty = total physical stock This invariant must hold after
12-
* every operation.
13-
*
14-
* <p>FAILURE SCENARIOS THIS ENABLES: - Out of stock: available_qty = 0 - Partial stock:
15-
* available_qty < requested for some items - Concurrent reservation: two checkouts race for the
16-
* same stock
17-
*/
188
@Entity
199
@Table(name = "inventory_item")
2010
@Getter

inventory-worker/src/main/java/com/example/inventory/domain/InventoryRepository.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,6 @@
1212
@Repository
1313
public interface InventoryRepository extends JpaRepository<InventoryItem, String> {
1414

15-
/**
16-
* Load an inventory item with a pessimistic write lock.
17-
*
18-
* <p>WHY PESSIMISTIC LOCK HERE? Two concurrent checkouts for the same product must not both
19-
* succeed if there's only enough stock for one. The pessimistic lock ensures only one transaction
20-
* can read-and-modify the row at a time.
21-
*
22-
* <p>Transaction 1: SELECT ... FOR UPDATE → gets lock, checks qty, reserves Transaction 2: SELECT
23-
* ... FOR UPDATE → BLOCKS until TX1 commits Transaction 2 then sees updated qty and may fail with
24-
* InsufficientStock.
25-
*
26-
* <p>FAILURE SCENARIO THIS HANDLES: "Concurrent reservation — two checkouts race for the same
27-
* stock"
28-
*/
2915
@Lock(LockModeType.PESSIMISTIC_WRITE)
3016
@Query("SELECT i FROM InventoryItem i WHERE i.productId = :productId")
3117
Optional<InventoryItem> findByIdForUpdate(String productId);

inventory-worker/src/main/java/com/example/inventory/domain/InventoryReservation.java

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,6 @@
88
import lombok.NoArgsConstructor;
99
import lombok.Setter;
1010

11-
/**
12-
* Records that inventory was reserved for a specific saga.
13-
*
14-
* <p>PURPOSE: Idempotency.
15-
*
16-
* <p>If reserveInventory() is called twice with the same sagaId (e.g. due to a retry), the second
17-
* call finds this record and returns immediately without modifying inventory quantities again.
18-
*
19-
* <p>WITHOUT THIS: A retry would double-reserve stock, corrupting inventory counts. WITH THIS: The
20-
* second call is a no-op. Safe to retry any number of times.
21-
*
22-
* <p>FAILURE SCENARIO THIS PREVENTS: "Inventory service crash mid-reservation — after DB write,
23-
* before response" On retry, the reservation record exists → skip → return success. No
24-
* double-reservation.
25-
*/
2611
@Entity
2712
@Table(name = "inventory_reservation")
2813
@Getter

inventory-worker/src/main/java/com/example/inventory/service/InventoryService.java

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,6 @@
1818
import lombok.RequiredArgsConstructor;
1919
import lombok.extern.slf4j.Slf4j;
2020

21-
/**
22-
* Real inventory reservation logic.
23-
*
24-
* <p>CONTRACTS:
25-
*
26-
* <p>1. ATOMICITY: Either ALL items are reserved or NONE are. Check all items first. Only modify
27-
* quantities if all checks pass. This prevents partial reservations that leave the system
28-
* inconsistent.
29-
*
30-
* <p>2. IDEMPOTENCY: If called twice with the same sagaId, the second call is a no-op. Check
31-
* InventoryReservation table before doing any work.
32-
*
33-
* <p>3. PESSIMISTIC LOCKING: Each product row is locked before reading qty. Prevents concurrent
34-
* checkouts from both seeing sufficient stock and both succeeding when only one should.
35-
*
36-
* <p>FAILURE SCENARIOS IMPLEMENTED: - Out of stock (prod_3): throws InsufficientStockException -
37-
* Partial stock (prod_2 with qty > 3): throws InsufficientStockException - Concurrent reservation:
38-
* pessimistic lock serializes access - Transient failure simulation: productId "prod_error" throws
39-
* TransientWorkerException - Idempotency: second call for same sagaId returns immediately
40-
*/
4121
@Slf4j
4222
@Service
4323
@RequiredArgsConstructor

0 commit comments

Comments
 (0)