Rules Hub
Coding Rules Library
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Make concurrency limits configurable, not magic numbers
Expose pool/batch concurrency as config with a sane default so it can be tuned without a redeploy.
Bad example
| 1 | const results = await promiseAllPool( |
| 2 | files.map((file) => () => processor.process(file)), |
| 3 | 8, // magic number; needs a code change to retune |
| 4 | ); |
Explanation (EN)
A hardcoded concurrency limit can't be adjusted when it overwhelms a downstream service or proves too conservative — every retune requires editing and redeploying code.
Objašnjenje (HR)
Hardkodiran limit konkurentnosti ne moze se prilagoditi kad preopterecuje servis nizvodno ili je prekonzervativan — svako ugadanje trazi izmjenu i redeploy koda.
Good example
| 1 | const CONCURRENCY = Number(process.env.PROCESS_CONCURRENCY) || 8; |
| 2 |
|
| 3 | const results = await promiseAllPool( |
| 4 | files.map((file) => () => processor.process(file)), |
| 5 | CONCURRENCY, |
| 6 | ); |
Explanation (EN)
Sourcing the limit from config with a documented default lets ops tune throughput against observed load without shipping code.
Objašnjenje (HR)
Dohvacanje limita iz konfiguracije s dokumentiranom zadanom vrijednoscu omogucuje ugadanje protoka prema stvarnom opterecenju bez izmjene koda.
Exceptions / Tradeoffs (EN)
A hardcoded constant is fine when the limit is dictated by a hard external constraint (e.g. a provider's documented max of N parallel connections) rather than tuning.
Iznimke / Tradeoffi (HR)
Hardkodirana konstanta je u redu kad limit diktira tvrdo vanjsko ogranicenje (npr. dokumentirani maksimum od N paralelnih veza kod providera), a ne ugadanje.