#concurrency

36 snippets tagged with #concurrency

typescriptadvanced

Node.js In-Memory Task Queue

A simple in-memory task queue with concurrency control, retries, and priority support.

Best for: Rate-limited API call processing

#nodejs#queue
typescriptintermediate

Promise Concurrency Patterns

Master Promise.all, allSettled, race, any — parallel execution with error handling and timeouts.

Best for: Parallel API calls with error handling

#nodejs#promise
typescriptintermediate

Semaphore for Concurrency Limiting

Control concurrent async operations with a semaphore pattern: rate limiting, connection pooling, and batch processing.

Best for: API rate limiting

#nodejs#concurrency
typescriptintermediate

Promise Pool for Batch Processing

Process large arrays with controlled concurrency using a promise pool pattern with progress tracking.

Best for: Bulk API requests

#nodejs#promise
typescriptadvanced

Promise Queue with Concurrency Limit

A queue that processes async tasks with a configurable concurrency limit to prevent resource exhaustion.

Best for: Rate-limited API calls

#async#concurrency
sqlintermediate

Optimistic Locking with Version Column

Prevent lost updates in concurrent environments using a version column for optimistic concurrency control.

Best for: Multi-user editing

#concurrency#locking
sqladvanced

SQL Transaction Isolation Levels

Understand and use transaction isolation levels to control concurrency and data consistency.

Best for: Preventing race conditions in financial transactions

#sql#transactions
pythonintermediate

asyncio.gather Concurrent Tasks

Run multiple async operations concurrently with asyncio.gather and proper error handling.

Best for: Parallel API calls

#asyncio#concurrency
pythonintermediate

Python Concurrent Futures for Parallel Work

Run tasks in parallel using ThreadPoolExecutor and ProcessPoolExecutor with error handling.

Best for: Parallel HTTP requests for web scraping

#python#concurrency
pythonadvanced

Run Async Tasks Concurrently with gather

Execute multiple async operations concurrently using asyncio.gather.

Best for: Parallel API calls

#python#asyncio
pythonadvanced

Asyncio Semaphore and Timeout Patterns

Control concurrency with asyncio semaphores, timeouts, and task groups for robust async code.

Best for: rate limiting API calls

#python#asyncio
pythonintermediate

Async ETL Pipeline with asyncio

Run concurrent data fetches and transformations using asyncio.gather for high-throughput pipelines.

Best for: concurrent API ingestion

#asyncio#async
javaintermediate

CompletableFuture — Async Programming

Chain async operations with CompletableFuture: thenApply, thenCompose, allOf, and exception handling.

Best for: Parallel API calls to multiple services

#java#async
javaadvanced

Virtual Threads — Lightweight Concurrency

Use Java 21 virtual threads for massive concurrency without thread pool tuning or reactive frameworks.

Best for: High-concurrency web servers handling thousands of requests

#java#virtual-threads
javaintermediate

ExecutorService — Thread Pool Management

Create and manage thread pools with ExecutorService: fixed, cached, scheduled, and custom pools.

Best for: Managing concurrent task execution

#java#concurrency
javaadvanced

Concurrent Collections — Thread-Safe Maps

Use ConcurrentHashMap, CopyOnWriteArrayList, and BlockingQueue for thread-safe data structures.

Best for: Thread-safe caching in multi-threaded applications

#java#concurrency
javaadvanced

Rate Limiter — Token Bucket Algorithm

Implement a thread-safe rate limiter using the token bucket algorithm for API throttling.

Best for: API rate limiting per user or IP

#java#rate-limiting
javaadvanced

Connection Pool Implementation

Build a generic connection pool with size limits, idle timeout, health checks, and metrics.

Best for: Database connection pooling

#java#connection-pool
javaadvanced

ThreadLocal and Scoped Values

Use ThreadLocal for per-thread data and ScopedValue (Java 21+) for structured concurrency contexts.

Best for: Request-scoped context in web servers

#java#threadlocal
javaintermediate

BlockingQueue — Producer Consumer Pattern

Implement producer-consumer with BlockingQueue: bounded buffers, multiple producers, and graceful shutdown.

Best for: Task queue processing systems

#java#concurrency
javaadvanced

Structured Concurrency (Java 21+)

Use StructuredTaskScope for parallel subtasks with automatic cancellation and error propagation.

Best for: Parallel API aggregation with auto-cancellation

#java#concurrency
javaintermediate

Semaphore — Concurrency Control

Control concurrent access with Semaphore: rate limiting, resource pools, and bounded parallelism.

Best for: Limiting concurrent API calls to external services

#java#semaphore
javaadvanced

Fork/Join Framework — Divide and Conquer

Parallelize recursive tasks with ForkJoinPool: RecursiveTask, RecursiveAction, and work-stealing.

Best for: CPU-intensive divide-and-conquer algorithms

#java#fork-join
javaadvanced

CompletableFuture Combinators — allOf, anyOf, compose

Compose async operations with CompletableFuture: allOf, anyOf, thenCombine, handle, and timeout.

Best for: Aggregating results from multiple microservices

#java#async
javaadvanced

Virtual Threads — Practical Patterns

Use Java 21 virtual threads for high-concurrency I/O: per-request threads, structured scopes, and limits.

Best for: High-concurrency I/O-bound servers

#java#virtual-threads
kotlinintermediate

Coroutines — launch, async, and Structured Concurrency

Write concurrent code with Kotlin coroutines: launch, async/await, structured concurrency, and dispatchers.

Best for: Parallel API calls in backend services

#kotlin#coroutines
kotlinadvanced

Channels — Producer-Consumer with Coroutines

Communicate between coroutines with Channels: produce, actor pattern, fan-out/fan-in, and select.

Best for: Producer-consumer patterns in coroutines

#kotlin#channels
kotlinadvanced

Structured Concurrency Patterns

Master coroutine structured concurrency: coroutineScope, async/await, fan-out/fan-in, and parallel map.

Best for: Parallel I/O operations with concurrency limits

#kotlin#coroutines
kotlinadvanced

Coroutine Channels Producer Consumer

Use Kotlin channels for coroutine communication: buffered, conflated, fan-out, and fan-in patterns.

Best for: Coroutine-based producer-consumer patterns

#kotlin#coroutines
kotlinadvanced

Coroutine Mutex and Synchronization

Synchronize shared mutable state in coroutines with Mutex, atomic operations, and thread confinement.

Best for: Thread-safe shared state in coroutines

#kotlin#coroutines
kotlinadvanced

Coroutine Select Expression

Use select expression to await the first result from multiple suspending operations or channels.

Best for: Racing multiple async operations

#kotlin#coroutines
scalaintermediate

Futures and Async Programming

Use Scala Futures for async operations: map, flatMap, recover, sequence, and race patterns.

Best for: Asynchronous API calls

#scala#futures
scalaintermediate

Parallel Processing with Collections

Process data in parallel using parallel collections, Future.traverse, and batched execution.

Best for: Speeding up CPU-bound operations

#scala#parallel
scalaadvanced

Akka Actor System Basics

Build concurrent applications with Akka actors: message passing, behavior switching, and supervision.

Best for: Concurrent message-passing systems

#scala#akka
scalaintermediate

Future Async Patterns

Work with Scala Futures: composition, error handling, timeout, retry, and parallel execution.

Best for: Asynchronous API calls

#scala#future
scalaadvanced

ZIO Fibers and Concurrency

Use ZIO fibers for lightweight concurrency: fork, join, race, parallel operations, and supervision.

Best for: Lightweight concurrent task execution

#scala#zio