Skip to content

Task 2-2: Retry Strategy cho Node Server Callbacks

Phase: 2 - Resilience Priority: Medium Depends on: Không có Reference: docs/BountyHunter-Backend/details/feature-payment-marketplace/SPEC.md

Background

NodeServerService nhận callbacks từ node server (NFT transfer, mint confirm). Nếu node server retry callback khi nhận timeout, backend phải handle idempotently. Ngoài ra, backend cũng có thể cần retry calls tới node server.

Tasks

DI Note: NodeServerService cần inject HTTP client (xác nhận là RestTemplate hay WebClient). Nếu dùng Spring Retry (@Retryable): đảm bảo @EnableRetry có trong @Configuration class và spring-retry dependency trong pom.xml. @Recover method phải cùng class, cùng return type, thêm exception type làm tham số đầu tiên.

  • [ ] Audit tất cả calls từ backend tới NodeServerService:

    grep -rn "confirmSolanaNftRental\|transferNft\|mintCompressNft" application-core/
    
    Xác nhận: confirmSolanaNftRental(), transferNft(), mintCompressNft() — các method khác nếu có

  • [ ] Thêm retry với exponential backoff cho outbound calls (cần spring-retry dependency):

    // Đảm bảo @EnableRetry trên @Configuration class
    @Retryable(
        value = {RestClientException.class},
        maxAttempts = 3,
        backoff = @Backoff(delay = 1000, multiplier = 2)  // 1s, 2s, 4s
    )
    public void confirmSolanaNftRental(String orderId, String tokenId, String renterAddress) {
        // call node server
    }
    
    @Recover
    public void confirmSolanaNftRentalFallback(RestClientException e, String orderId,
        String tokenId, String renterAddress) {
        LOGGER.error("[NODE_SERVER] Failed to confirm rental after 3 retries. orderId={}", orderId, e);
        // Store for manual retry / alert ops team
    }
    

  • [ ] Apply tương tự cho transferNft()mintCompressNft()

  • [ ] Document callback idempotency: node server có thể retry → backend phải idempotent (task-1-1 đã cover inbound idempotency)

Verification / Acceptance Criteria

  • [ ] spring-retry dependency tồn tại trong pom.xml (nếu dùng @Retryable)
  • [ ] @EnableRetry tồn tại trong một @Configuration class
  • [ ] Khi node server trả 5xx/timeout → retry tối đa 3 lần với backoff
  • [ ] Sau 3 lần fail → @Recover method được gọi, error được log với orderId
  • [ ] Happy path: retry không ảnh hưởng khi call thành công lần đầu

Files to Modify

  • application-core/service/node_server/NodeServerService.java