Code Explainers
Code explainers tagged #batching
rust
use axum::{extract::State, response::IntoResponse, Json}; use serde::{Deserialize, Serialize}; use serde_json::{json, Value}; use std::sync::Arc;
Building a JSON-RPC 2.0 handler in Axum
json-rpc
serde
request-dispatch
Intermediate
8 steps
javascript
async function uploadInBatches(records, uploadFn, { batchSize = 100, concurrency = 3 } = {}) { const batches = []; for (let i = 0; i < records.length; i += batchSize) { batches.push(records.slice(i, i + batchSize));
Uploading records with bounded concurrency
concurrency
worker-pool
async-await
Advanced
8 steps
go
package batch import "fmt"
Splitting a slice into batches in Go
generics
slices
error-handling
Intermediate
6 steps
ruby
class Debouncer def initialize(delay:) @delay = delay @mutex = Mutex.new
A thread-safe debouncer in Ruby
concurrency
debouncing
mutex
Advanced
5 steps
ruby
class Admin::OrdersExportController < Admin::BaseController include ActionController::Live def show
Streaming a CSV export in Rails
streaming
csv-export
batching
Advanced
8 steps
javascript
const MAX_BATCH_SIZE = 20; const FLUSH_INTERVAL = 5000; const ENDPOINT = '/api/analytics';
Batching analytics events in the browser
batching
buffering
sendbeacon
Intermediate
10 steps
java
@Controller public class BookController { private final BookService bookService;
Solving GraphQL N+1 with batch mapping in Spring
graphql
n+1-problem
batching
Intermediate
8 steps
go
func (r *EventRepository) BatchInsert(ctx context.Context, events []Event) error { if len(events) == 0 { return nil }
Batch inserting rows in a Go transaction
transactions
batching
database
Intermediate
7 steps
go
type SensorReading struct { DeviceID string `json:"device_id" binding:"required"` Temperature float64 `json:"temperature"` RecordedAt time.Time `json:"recorded_at" binding:"required"`
Streaming NDJSON ingestion in Gin
streaming
batching
json-decoding
Advanced
10 steps
ruby
class BulkImporter BATCH_SIZE = 500 def initialize(records)
Batching bulk inserts in Rails
batching
bulk-insert
deduplication
Intermediate
5 steps
java
public class OrderRepository { private static final int BATCH_SIZE = 500; private static final String INSERT_SQL =
Batched JDBC inserts with transaction safety
jdbc
batching
transactions
Intermediate
8 steps
java
@Component @Order(20) public class ProductSearchIndexRunner implements ApplicationRunner {
Rebuilding a search index at Spring startup
startup-hook
batching
streaming
Intermediate
8 steps
typescript
type Event = Record<string, unknown>; interface BatcherOptions { endpoint: string;
Batching analytics events in TypeScript
batching
buffering
async
Intermediate
8 steps
javascript
class DOMBatcher { constructor() { this.reads = []; this.writes = [];
Batching DOM reads and writes to avoid layout thrash
batching
requestanimationframe
layout-thrashing
Intermediate
8 steps
php
final class UserActivityStream { public function __construct( private readonly \PDO $db,
Streaming user activity with PHP generators
generators
pagination
lazy-evaluation
Intermediate
8 steps
rust
use std::collections::HashMap; #[derive(Debug, Clone)] struct Record {
Batched aggregation with fold in Rust
iterators
fold
hashmap
Intermediate
9 steps
ruby
class PurgeStaleExportsJob < ApplicationJob queue_as :maintenance retry_on ActiveRecord::Deadlocked, wait: :polynomially_longer, attempts: 5
Purging stale exports with an Active Job in Rails
background-jobs
batching
error-handling
Intermediate
7 steps
php
public function importUsers(array $users): int { $inserted = 0;
Bulk-inserting users with batched PDO upserts
batching
bulk-insert
prepared-statements
Intermediate
6 steps