idempotency

typescript
import { Module } from '@nestjs/common';
import { BullModule } from '@nestjs/bull';
import { ScheduleModule } from '@nestjs/schedule';
import { DigestProducer } from './digest.producer';
import { DigestProcessor } from './digest.processor';

Scheduling and Processing Email Digests with a Bull Queue in NestJS

nestjs bull redis
by codesnips 3 tabs
javascript
const express = require('express');
const { enqueueEmail } = require('./emailQueue');

const router = express.Router();

router.post('/users/:id/welcome-email', async (req, res, next) => {

Reliable Background Email Jobs With BullMQ, Redis, and a Worker Process

bullmq redis background-jobs
by codesnips 3 tabs
sql
CREATE TABLE idempotency_keys (
    request_key         text        NOT NULL,
    endpoint            text        NOT NULL,
    request_fingerprint text        NOT NULL,
    status              text        NOT NULL DEFAULT 'in_progress'
                                    CHECK (status IN ('in_progress', 'completed')),

Idempotency keys for “create” endpoints

reliability postgres idempotency
by codesnips 3 tabs
python
import hashlib
import hmac
import time


class SignatureError(Exception):

Verify Stripe-Style Webhook HMAC Signatures Before Processing in Flask

flask webhooks hmac
by codesnips 3 tabs
php
<?php

namespace App\Console\Commands;

use App\Jobs\CompileReportJob;
use Carbon\CarbonImmutable;

Schedule a Recurring Report Job in Laravel's Console Kernel

laravel scheduler cron
by codesnips 3 tabs
ruby
class CreateAccountsAndLedger < ActiveRecord::Migration[7.1]
  def change
    create_table :accounts do |t|
      t.string :name, null: false
      t.string :currency, null: false, default: "USD"
      t.bigint :balance_cents, null: false, default: 0

Atomic Account Transfers in Rails With Row Locks and a Balance Service

rails postgres transactions
by codesnips 4 tabs
ruby
class CreateIdempotencyKeys < ActiveRecord::Migration[7.1]
  def change
    create_table :idempotency_keys do |t|
      t.string :key, null: false
      t.string :request_path, null: false
      t.datetime :locked_at

Idempotent Form Submissions in Rails with an Idempotency-Key Column and before_action Guard

rails idempotency postgres
by codesnips 4 tabs
typescript
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';

async function bootstrap() {
  // rawBody: true preserves the exact bytes Stripe signed
  const app = await NestFactory.create(AppModule, { rawBody: true });

Verify Stripe Webhook Signatures in a NestJS Guard Before the Handler

nestjs webhooks stripe
by codesnips 4 tabs
typescript
import type { Redis } from "ioredis";

export interface StoredResponse {
  status: "pending" | "completed";
  fingerprint: string;
  httpStatus?: number;

Idempotent POST Requests in Express with a Redis-Backed Middleware

express redis idempotency
by codesnips 3 tabs
ruby
module DefensiveDeserialization
  extend ActiveSupport::Concern

  MissingRecord = Struct.new(:gid) do
    def missing?
      true

Defensive Deserialization for ActiveJob

rails activejob reliability
by codesnips 3 tabs
php
<?php

namespace App\Providers;

use App\Events\OrderPlaced;
use App\Listeners\DecrementInventory;

Fan Out an Order Placed Domain Event to Multiple Queued Laravel Listeners

laravel events queues
by codesnips 4 tabs
python
import uuid
from django.db import models
from django.utils import timezone


class OutboxManager(models.Manager):

Transactional Outbox with Timer-Based Flushing and Exponential Backoff in Django

django outbox postgres
by codesnips 3 tabs