reliability

ruby
class ExportWriter
  def initialize(export)
    @export = export
  end

  def append(rows)

Chaining Dependent GoodJob Jobs with a Callback-Scheduled Continuation

rails good-job background-jobs
by codesnips 3 tabs
java
@Entity
@Table(name = "idempotency_records",
       uniqueConstraints = @UniqueConstraint(columnNames = "idempotency_key"))
public class IdempotencyRecord {

    public enum Status { IN_PROGRESS, COMPLETED }

Idempotent POST Handling in Spring Boot with a Stored Idempotency-Key

spring-boot idempotency rest-api
by codesnips 3 tabs
ruby
module QueryBudget
  class Counter
    IGNORED = %w[SCHEMA CACHE TRANSACTION].freeze

    attr_reader :count

Per-Request Query Budget (Detect Runaway Pages)

rails performance observability
by codesnips 4 tabs
php
<?php

namespace App\Jobs;

use App\Models\Invoice;
use App\Services\StripeGateway;

Preventing Double-Charges in Laravel with WithoutOverlapping Job Middleware

laravel queues background-jobs
by codesnips 3 tabs
go
package webhook

import (
	"encoding/json"
	"io"
	"net/http"

Verifying and Dispatching Stripe-Style Webhooks by Event Type in Go

webhooks go hmac
by codesnips 3 tabs
javascript
const withTimeout = (promise, timeoutMs, name) => {
  let timer;
  const timeout = new Promise((_, reject) => {
    timer = setTimeout(
      () => reject(new Error(`check '${name}' timed out after ${timeoutMs}ms`)),
      timeoutMs

Express Health-Check Router With a Pluggable Dependency Checks Registry

express health-check observability
by codesnips 3 tabs
ruby
class SlidingWindowLimiter
  Result = Struct.new(:allowed, :count, :limit, :window_ms, keyword_init: true)

  SCRIPT = <<~LUA.freeze
    local key = KEYS[1]
    local now = tonumber(ARGV[1])

Rate Limiting with Redis + Increment Expiry

rails redis reliability
by codesnips 3 tabs
java
@Configuration
public class TxConfig {

    @Bean
    public PlatformTransactionManager transactionManager(DataSource dataSource) {
        DataSourceTransactionManager tm = new DataSourceTransactionManager(dataSource);

Multi-Step Order Flow With Spring TransactionTemplate and Savepoint Rollback

spring-boot transactions transactiontemplate
by codesnips 3 tabs
javascript
class ApiError extends Error {
  constructor(statusCode, message, code) {
    super(message);
    this.name = 'ApiError';
    this.statusCode = statusCode;
    this.code = code || null;

Centralized Async Error Handling in Express With asyncHandler and Error Middleware

express nodejs error-handling
by codesnips 4 tabs
go
package mailer

import (
	"crypto/sha256"
	"encoding/hex"
	"strings"

Idempotent Email Sending with a Redis Fingerprint Set in Go

redis idempotency email
by codesnips 3 tabs
go
package cleanup

import "errors"

func CloseAll(closers ...func() error) error {
  var errs []error

errors.Join for cleanup (surface multiple close failures)

go errors reliability
by Leah Thompson 1 tab
go
package limit

import (
  "context"

  "golang.org/x/sync/semaphore"

Concurrency limiting with a context-aware semaphore

go concurrency context
by Leah Thompson 1 tab