Code Explainers

Code explainers tagged #idempotency

go
package middleware
 
import (
	"bytes"

Idempotent requests in Gin with Redis

idempotency caching middleware
Advanced 10 steps
php
<?php
 
namespace App\Http\Middleware;
 

Idempotency keys in Laravel middleware

idempotency middleware caching
Advanced 8 steps
rust
use axum::{
    extract::State,
    http::StatusCode,
    Json,

Idempotent webhook handling in Axum

deduplication idempotency shared-state
Intermediate 8 steps
python
import json
import hashlib
from datetime import timedelta
 

Idempotent payment endpoints in FastAPI

idempotency redis distributed-locking
Advanced 9 steps
php
<?php
 
namespace App\Http\Middleware;
 

Idempotent requests with Laravel middleware

idempotency middleware caching
Advanced 8 steps
javascript
export function diffIds(current, desired) {
  const currentSet = new Set(current);
  const desiredSet = new Set(desired);
 

Diffing sets to sync group membership

set-operations diffing transactions
Intermediate 8 steps
rust
use axum::{
    async_trait,
    extract::{FromRequestParts, State},
    http::{request::Parts, StatusCode},

Idempotent payments with an Axum extractor

idempotency extractors shared-state
Intermediate 8 steps
ruby
class OrdersController < ApplicationController
  rescue_from ActiveRecord::RecordNotUnique, with: :handle_duplicate_submission
 
  def create

Idempotent order creation in Rails

idempotency database-constraints error-handling
Intermediate 8 steps
php
<?php
 
namespace App\Jobs;
 

Building a unique queued job in Laravel

queues background-jobs idempotency
Intermediate 7 steps
php
<?php
 
namespace App\Jobs;
 

Serializing balance reconciliation in Laravel

queues concurrency idempotency
Intermediate 7 steps
java
@Aspect
@Component
public class IdempotencyAspect {
 

How an idempotency aspect works in Spring

aop idempotency caching
Advanced 9 steps
typescript
import { useEffect, useRef, useCallback } from "react";
 
type DraftPayload = Record<string, unknown>;
 

A debounced auto-save hook in React

debouncing request-cancellation refs
Advanced 7 steps
java
package com.example.orders.messaging;
 
import com.example.orders.dto.OrderEvent;
import com.example.orders.service.OrderProcessingService;

Manual RabbitMQ acks in a Spring listener

message-queue error-handling acknowledgement
Intermediate 6 steps
ruby
class CartMergeService
  def initialize(guest_cart:, user_cart:)
    @guest_cart = guest_cart
    @user_cart = user_cart

Merging a guest cart into a user cart in Rails

service object transactions idempotency
Intermediate 7 steps
ruby
class SearchIndexReconciler
  DEBOUNCE_WINDOW = 5.seconds
 
  def self.schedule(record)

Debouncing search reindex jobs in Rails

debouncing background-jobs caching
Advanced 7 steps
python
import json
import logging
 
import stripe

Handling Stripe webhooks in Django

webhooks signature-verification idempotency
Intermediate 7 steps
ruby
class PaymentsController < ApplicationController
  before_action :require_idempotency_key
 
  def create

Idempotent payment creation in Rails

idempotency transactions race-conditions
Advanced 10 steps
ruby
class OrderConfirmationJob < ApplicationJob
  queue_as :mailers
 
  retry_on Net::OpenTimeout, wait: :polynomially_longer, attempts: 5

Resilient background jobs in Rails

background-jobs retries idempotency
Intermediate 8 steps