Architecture & responsibilities
- Tech stack: Java 21, Spring Boot 3.5, RabbitMQ, MySQL, Jackson, Jakarta Validation, SLF4J/Logback.
- Queues: primary
PAYMENTS.WEBHOOK.QUEUE; delay/TTL queuePAYMENTS.WEBHOOK.DELAY.QUEUEfor retries. - Database: tracks notification status, attempt count, and last sent timestamp per payment.
- Health/metrics: Spring Actuator endpoints (health, metrics, flyway).
Input payload (from RabbitMQ)
Example message consumed from the queue (validated before processing):payment_idpositive and present.payment_uuid,client_reference,callback_urlnon-blank.amountnon-negative.- Violations throw a validation exception and are not re-queued.
Notification payload (to your callback)
Transformed JSON sent via HTTPPOST to callback_url. See Webhook payload for full schema; example:
100 CREATED, 101 PENDING, 102 SUCCESS, 103 FAILED, 104 ESCALATED, 105 EXPIRED, 106 REFUNDED, 107 REVERSED).
Processing flow
- Consume from
PAYMENTS.WEBHOOK.QUEUE(orPAYMENTS.WEBHOOK.DELAY.QUEUEfor retries). - Validate via Bean Validation; invalid messages are rejected (no requeue).
- Attempts guard: if
attempts >= maxAttempts(default 3), mark failed and stop. - Build notification payload with
validation_hashandtime_processed. - Send HTTP POST to
callback_url(treat 200/201/202 as success). - Persist: on success set
notification_status = SUCCESS, store attempts + timestamp; on failure increment attempts and markNOT_SENT. - Retry: publish failures to
PAYMENTS.WEBHOOK.DELAY.QUEUE(TTL default 60s) before returning to the primary queue. - Error handling: HTTP/network errors retry; DB errors log/rollback; validation errors stop processing.
Integrity check (validation_hash)
- Computed as SHA-256 over
amount + client_reference + payment_uuid + payment_id. - Included in
results.validation_hashso you can recompute and verify. See Verify signature for verification snippets and stronger HMAC guidance.
Operational notes
- Concurrency: Rabbit listener concurrency is tunable (e.g., 25–100 consumers) with prefetch=1 to balance throughput and fairness.
- Durability: Queues are durable; delay queue handles backoff. Maximum attempts and delay are configurable (
webhook.max-attempts,webhook.delay-seconds). - Observability: Structured logs (SLF4J/Logback) include payment identifiers for traceability. Actuator endpoints expose health/metrics; integrate with your logging/monitoring stack.
- Deployment: Containerized Spring Boot service; config driven by environment-specific
application-*.yml. Scales horizontally (multiple consumers) as RabbitMQ distributes messages.
Assumptions & limitations
- Requires reachable RabbitMQ and MySQL backends; callback URLs must accept HTTPS
POSTwith JSON. - Fixed retry delay (default 60s) and max attempts (default 3); adjust if your outage patterns require different backoff.
- Validation failures are dropped (not requeued); add a dead-letter queue if you need to capture malformed messages.
- Uses a simple SHA-256 hash for integrity; for stronger guarantees, migrate to HMAC with per-client secrets.
