transactions

java
package com.shop.orders.events;

import java.math.BigDecimal;
import java.time.Instant;

public record OrderPlacedEvent(

Transactional Domain Events With Spring's ApplicationEventPublisher and @TransactionalEventListener

spring spring-boot domain-events
by codesnips 4 tabs
go
package store

import (
  "context"

  "github.com/jackc/pgx/v5"

Row-level locking with SELECT ... FOR UPDATE in a transaction

go postgres transactions
by Leah Thompson 1 tab
typescript
import { QueryResultRow } from 'pg';
import { pool, Queryable } from './db';

export abstract class BaseRepository<T extends QueryResultRow> {
  protected abstract readonly table: string;

Repository pattern for DB access (small, pragmatic)

node postgres architecture
by codesnips 4 tabs
ruby
class Order < ApplicationRecord
  class InvalidTransition < StandardError; end

  enum status: { pending: 0, paid: 1, shipped: 2, cancelled: 3 }

  has_many :order_transitions, -> { order(:created_at) }, dependent: :destroy

Order State Machine With Guarded Transitions and an Audit Trail in Rails

rails state-machine activerecord
by codesnips 3 tabs
javascript
const { pool } = require('./db');

async function recordEvent(client, { eventId, type, payload }) {
  const { rows } = await client.query(
    `INSERT INTO webhook_events (event_id, type, payload, status)
     VALUES ($1, $2, $3, 'received')

Idempotent Stripe Webhook Processing With an Express Event-Store Middleware

express webhooks idempotency
by codesnips 3 tabs
java
import jakarta.persistence.*;
import java.math.BigDecimal;
import java.util.Objects;

@Entity
@Table(name = "accounts")

Optimistic Locking with JPA @Version and Retry on Concurrent Updates

jpa hibernate spring
by codesnips 3 tabs
ruby
module EventBus
  @subscribers = Hash.new { |h, k| h[k] = [] }

  class << self
    def subscribe(event_class, handler = nil, &block)
      callable = handler || block

In-Process Domain Event Bus with Subscribers in Rails

rails domain-events event-bus
by codesnips 4 tabs