Labs Ledgerline
- SpecShield Labs
- Internal demo
- Synthetic data
- Status: in build
Ledgerline
Reliable order & payment event processing
Duplicate, forged and out-of-order payment webhooks change order state exactly once, with signed outbound notifications and replay.
1. Engagement type and status
- Engagement type
- Internal engineering demonstration (SpecShield Labs). Built in the open, with synthetic data only.
- Comparable client offer
- Engineering sprint (2–3 weeks)
- Status
- in build
2. Problem and intended buyer
- Payment providers retry webhooks. If the same event is processed twice, an order ships twice or is refunded twice.
- Events arrive out of order. A late "payment failed" must not overwrite an order that is already paid.
- Forged or replayed webhooks must be rejected without changing any state.
- Writing to the database and notifying another system in two steps (dual write) loses or duplicates messages when one step fails.
Who this is for: A CTO or engineering lead at a US SaaS or commerce company whose payment, order or fulfillment events are occasionally applied twice, lost, or applied in the wrong order.
3. Scope and exclusions
In scope
- Orders API with Stripe-style Idempotency-Key handling, safe under concurrent retries.
- Signed inbound webhooks (HMAC-SHA256 over timestamp and raw body, 300-second tolerance, key rotation).
- Inbox table with a unique constraint, so each provider event changes state once.
- Explicit order state machine that marks out-of-order events as stale instead of applying them.
- Transactional outbox to signed outbound webhooks, with retries, jitter, a dead-letter queue and manual replay.
- Chaos scenarios and an audit timeline that make each failure mode visible.
Excluded
- Not a payment system. No card data is collected, stored or processed, and it is not PCI DSS scoped.
- MockPay is a simulator built into the demo, not a real payment provider.
- Single region, single database. No multi-region failover.
- No real merchants, customers or orders. All data is synthetic and resets daily at 03:00 UTC.
4. Architecture and key decisions
[React Ops Console] ──REST──▶ [Ledgerline API (Spring Boot 4)]
│ orders · idempotency · admin
[MockPay simulator] ──signed──▶ /webhooks/mockpay ─▶ inbox (dedupe)
(in-process module, │ └─▶ state machine ─▶ orders
sends real HTTP) │ └─▶ outbox (same tx)
▼
[Outbox dispatcher] ──signed──▶ merchant endpoint
retry+jitter · DLQ · replay (mock sink)
PostgreSQL 17 · Micrometer/OTel · /actuatorKey decisions
Inbox table with a unique constraint, not a cache
Deduplication lives in PostgreSQL in the same transaction as the state change, so a crash cannot record an event as seen without applying it.
Transactional outbox instead of dual writes
The notification row is committed with the order change. A dispatcher delivers it at least once; consumers deduplicate by event ID.
PostgreSQL SKIP LOCKED instead of a message broker
One fewer system to run at demo scale. The outbox can move to Kafka or SQS later without changing the domain.
5. Video and screenshots
The 2-minute walkthrough video is published when the demo is live.
Screenshots are added when the ops console ships.
Break our webhook handler
Each button sends real, signed HTTP webhooks to the Ledgerline internal demo, then shows what the service did with them. Synthetic data only.
What to watch for: Received → Applied → PAID.
What to watch for: 5 deliveries, 1 state change, 4 duplicates blocked.
What to watch for: Signature rejected. Order state unchanged.
What to watch for: Late "payment failed" marked stale. Order stays PAID.
6. Tests and measured results
Numbers below come from the repository's CI evidence file. A metric without a published run reads "not measured".
| Metric | Value |
|---|---|
| Last build | Passing |
| Tests (total / failed) | 371 / 0 |
| Unit / integration / end-to-end | 226 / 134 / 11 |
| Line coverage (overall / domain) | 95% / 100% |
| Mutation score | 90% |
| Load test p95 | not measured |
| Load test environment | not measured |
| CodeQL | Pass |
| Trivy critical vulnerabilities | 0 |
| ZAP high alerts | not measured |
| SBOM | Download (CycloneDX) |
| Commit | e360215 |
| Built at | Nov 24, 2026, 8:43 PM UTC |
What the test suite proves
- LL-I0850 concurrent deliveries of one event change the order once, with 49 duplicate responses and 0 errors.
- LL-P01Property test. Any duplicated and shuffled event history ends in the same state as the canonical history.
- LL-I0410 concurrent POSTs with one Idempotency-Key create exactly 1 order.
- LL-U11Signatures more than 300 seconds old or in the future are rejected.
- LL-I17Two dispatchers over 200 outbox rows deliver each row exactly once.
- LL-N01k6 load test at 200 requests/s with 20% duplicates; each event ID is applied once.
7. Security and limitations
Security controls
- Constant-time signature comparison against every configured secret; secrets and full signatures are never logged.
- Admin endpoints require authentication; public endpoints are rate limited.
- Request bodies are capped at 64 KB; unexpected content types are rejected.
- Every error response uses RFC 9457 problem+json without stack traces.
Known limitations
- Rate limiting is in memory, so limits are per instance.
- Admin uses HTTP Basic auth from environment variables, which is fine for a demo but not for production.
- Outbound delivery is at least once. Consumers must deduplicate by Ledgerline-Event-Id.
- Measured results come from a GitHub-hosted runner, not production hardware.
8. Code tour
Files worth reading first:
- domain/OrderStateMachine.java
Every allowed transition in one pure class, and what counts as stale.
- application/IdempotencyService.java
Stripe-style key handling, including concurrent requests with the same key.
- webhook/ (signature verification and receiver)
Raw-body HMAC verification, tolerance window and inbox dedupe in one transaction.
- outbox/OutboxDispatcher.java
SKIP LOCKED batching, at-least-once delivery and crash recovery.
- outbox/BackoffPolicy.java
Exponential backoff with full jitter as a pure, testable class.
Have duplicate-event problems?
Book a free 30-minute integration health check. A senior engineer looks at how your system handles retries, ordering and signatures.