Skip to content

Instantly share code, notes, and snippets.

View asim-altayb's full-sized avatar
🎯
Focusing

Asim Altayb asim-altayb

🎯
Focusing
View GitHub Profile
@asim-altayb
asim-altayb / 06-postgres-immutable-ledger.md
Created July 13, 2026 23:27
PostgreSQL immutable-ledger constraints

PostgreSQL immutable-ledger constraints

Context: Double-entry audit rows must not be quietly edited after the fact. Where used: https://github.com/asim-altayb/spring-payments-platform

Schema guards

create unique index one_entry_per_side on ledger_entries (transfer_id, direction);
-- direction in ('DEBIT','CREDIT'), amount > 0
@asim-altayb
asim-altayb / 05-hmac-webhook-signing.md
Created July 13, 2026 23:27
HMAC webhook signing and verification
@asim-altayb
asim-altayb / 04-spring-security-jwt-scopes.md
Created July 13, 2026 23:27
Spring Security JWT scope configuration

Spring Security JWT scope configuration

Context: Protect account/transfer APIs with OAuth2 resource-server scopes. Where used: https://github.com/asim-altayb/spring-payments-platform

Filter chain

http.authorizeHttpRequests(auth -> auth
        .requestMatchers("/actuator/health/**", "/openapi.yaml").permitAll()
@asim-altayb
asim-altayb / 03-optimistic-concurrency-retry.md
Created July 13, 2026 23:27
Optimistic concurrency and safe retry
@asim-altayb
asim-altayb / 02-outbox-skip-locked.md
Created July 13, 2026 23:27
Transactional outbox worker with `FOR UPDATE SKIP LOCKED`

Transactional outbox worker with FOR UPDATE SKIP LOCKED

Context: Publish integration events only if the business transaction committed. Where used: https://github.com/asim-altayb/spring-payments-platform

Why

Writing to the DB and calling HTTP/Kafka in the same request loses events on crash after commit or double-sends on retry. The outbox stores the event in the same transaction as the business write; a worker publishes asynchronously.

Claim query

@asim-altayb
asim-altayb / 01-spring-postgres-idempotency.md
Created July 13, 2026 23:27
Spring / PostgreSQL idempotency pattern

Spring / PostgreSQL idempotency pattern

Context: Account-to-account transfers must tolerate client retries without moving money twice. Where used: https://github.com/asim-altayb/spring-payments-platform

Pattern

  1. Client sends Idempotency-Key + stable client_id.
  2. Service looks up (client_id, idempotency_key) first.
  3. On miss, insert transfer row under a unique constraint.

These are my notes on how I got all the basics working end to end.

Laravel API backend and Vue.js frontend are 2 different servers on different public IP addresses and different domains. I am using pure Vue.js on the front end. Most instructions assume Laravel Vue.js is being used which is structured slightly different with different file names and directories.

  • Laravel API backend domain name (api.somedomain.com)
  • Vue.js frontend domain name (client.somedomain.com)

No database is needed for any of this to work using sync queue. That is only needed in production if/when you use a database queue.


<script lang="ts">
import { useIntersectionObserver } from "@vueuse/core";
import { ref, nextTick } from "vue";
function onIdle(cb = () => {}) {
if ("requestIdleCallback" in window) {
window.requestIdleCallback(cb);
} else {
setTimeout(() => {
nextTick(cb);