reliability

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
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
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 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
java
import java.time.Duration;
import java.util.concurrent.ThreadLocalRandom;
import java.util.function.Predicate;

public final class RetryPolicy {
    private final int maxAttempts;

Async Retry With Exponential Backoff and Full Jitter Using ScheduledExecutorService

java retry backoff
by codesnips 3 tabs
go
package migrate

import (
  "context"

  "github.com/jackc/pgx/v5/pgxpool"

Run database migrations on startup (with a guard)

go postgres migrations
by Leah Thompson 1 tab
ruby
class CircuitBreaker
  class CircuitOpenError < StandardError; end

  def initialize(name, redis: Redis.current, failure_threshold: 5, failure_window: 60, cooldown: 30)
    @key = "circuit:#{name}"
    @redis = redis

Service-Level “Circuit Breaker” (Simple)

rails reliability http
by codesnips 3 tabs