SShortSingh.
Back to feed

How to Build Reliable Scheduled Background Jobs in Node.js Using Cron and Queues

0
·1 views

A recommended Node.js architecture separates cron triggers from long-running background work by having the scheduler publish small, bounded tasks to a queue rather than executing full fanout processes inline. Each delivery task is represented as a durable database record containing a shipment ID, subscriber ID, event version, and a stable deduplication key to ensure retries remain safe. A unique database constraint — not an in-memory store — enforces deduplication, since process-local state is lost on restarts and can cause duplicate deliveries across multiple workers. Workers claim individual delivery records atomically, send the update to the relevant subscriber, and mark the exact version as delivered, creating a built-in audit trail for support and compliance purposes. This approach is especially critical in healthtech workflows, where a single shipment status event may fan out to dozens of subscribers and a duplicate notification could confuse patients or trigger unintended downstream actions.

Read the full story at DEV Community

This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)

Log in to join the discussion and vote.

Log in

Related stories

0
ProgrammingDEV Community ·

CTEs vs Subqueries: SQL Optimizers Treat Them Almost Identically

A common belief among developers is that Common Table Expressions (CTEs) are inherently faster than subqueries, but this is largely a myth in modern SQL Server and PostgreSQL. Both CTEs and derived tables are typically expanded into the same relational tree by the query optimizer, producing identical execution plans and I/O costs. However, when a CTE is referenced multiple times within a single query, SQL Server may execute its underlying logic more than once or create a Lazy Spool in tempdb, adding overhead. In such cases, using a temporary table with an explicit clustered index is recommended for handling large, multi-million-row datasets. Understanding these internals helps engineers make more informed decisions when designing data pipelines.

0
ProgrammingDEV Community ·

Developer Builds Browser-Based Byte Decoder to Avoid Third-Party Privacy Risks

A developer has shared a lightweight, client-side tool that decodes raw byte sequences into readable text entirely within the browser, eliminating the need for third-party online decoders. The utility is built using JavaScript's native TextDecoder API and Uint8Array, supporting both decimal and hexadecimal input formats. It is designed for use cases such as debugging network streams, parsing custom file formats, and inspecting database buffers. The tool decodes byte sequences using UTF-8 encoding, making it compatible with modern web standards including emojis and multilingual scripts. By processing all data locally in browser memory, the converter avoids the data privacy risks associated with pasting sensitive byte sequences into external services.

0
ProgrammingDEV Community ·

okf-guard Python library scans documents for hidden prompt injection before AI ingestion

A new open-source Python library called okf-guard aims to protect AI agent pipelines from indirect prompt injection attacks embedded in source documents. The tool targets a specific vulnerability where hidden text in common file formats — such as PDFs, Word documents, spreadsheets, and presentations — gets extracted alongside legitimate content and fed to AI systems without distinction. okf-guard supports six file formats and runs two independent checks on each scan: one for hidden content and one for injection-style phrasing, flagging either finding separately. The library is particularly relevant to Google's recently published Open Knowledge Format (OKF), which has AI agents read markdown files directly with no intermediate processing layer. All detection is rule-based and fully deterministic, with no LLM dependency or network calls, making its behavior reproducible and auditable.

0
ProgrammingDEV Community ·

Tutorial Proposes Consent-Based Memory Design for AI Voice Companions

A software design tutorial published on DEV Community argues that AI voice companions should treat user memory as a consent ledger rather than a passive prompt history. The approach requires the AI model to propose a typed fact, which the user must explicitly confirm, correct, or reject before it can be stored. Only confirmed records are permitted to enter future prompts sent to a large language model. The design restricts storable data to a small set of bounded slots—such as preferred name, music genre, and chat style—deliberately excluding free-form instructions or sensitive personal data. The tutorial demonstrates the implementation in TypeScript, integrated with Tencent RTC's Conversational AI platform, emphasizing that the application, not the model, should control what becomes durable memory.

How to Build Reliable Scheduled Background Jobs in Node.js Using Cron and Queues · ShortSingh