{"product_id":"n8n-mutex-lease-tokens-for-hierarchical-namespaces-rate-limit","title":"n8n Mutex Lease Tokens for Hierarchical Namespaces + Rate Limit","description":"\u003ch3\u003eLock hierarchical namespaces in n8n with mutex lease tokens (plus optional rate limiting)\u003c\/h3\u003e\n\u003cp\u003eThis sub-workflow acquires a mutex-style \u003cstrong\u003elease token\u003c\/strong\u003e for a dot-separated namespace (e.g., \u003cem\u003ea.b\u003c\/em\u003e) using an \u003cstrong\u003en8n Data Table\u003c\/strong\u003e. It can also enforce a \u003cstrong\u003etoken-bucket rate quota\u003c\/strong\u003e per namespace level—then returns the token, the claimed chain, and lease expiry details.\u003c\/p\u003e\n\n\u003ch3\u003eWhat this workflow does\u003c\/h3\u003e\n\u003cul\u003e\n  \u003cli\u003e\n\u003cstrong\u003eAccepts a required mutex namespace\u003c\/strong\u003e from a calling workflow (for example, \u003cem\u003ea.b\u003c\/em\u003e).\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eExpands the namespace into a hierarchical chain\u003c\/strong\u003e (e.g., \u003cem\u003ea\u003c\/em\u003e and \u003cem\u003ea.b\u003c\/em\u003e) and uses the \u003cstrong\u003ecurrent execution ID\u003c\/strong\u003e as the candidate lock token.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eChecks the n8n Data Table\u003c\/strong\u003e for each chain level to see whether a lock is already leased or whether a configured rate window has been exceeded.\u003c\/li\u003e\n  \u003cli\u003eIf not available, it \u003cstrong\u003ewaits and re-checks\u003c\/strong\u003e (up to \u003cstrong\u003e10 seconds\u003c\/strong\u003e for busy locks, or until the rate window resets).\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eUpserts\u003c\/strong\u003e each namespace level in the Data Table with:\n    \u003cul\u003e\n      \u003cli\u003e\n\u003ccode\u003ecurrentToken\u003c\/code\u003e (token based on execution ID)\u003c\/li\u003e\n      \u003cli\u003e\n\u003ccode\u003evalidUntil\u003c\/code\u003e set to a \u003cstrong\u003e60-second lease\u003c\/strong\u003e\n\u003c\/li\u003e\n      \u003cli\u003eupdated rate-limit counters when rate limiting is enabled\u003c\/li\u003e\n    \u003c\/ul\u003e\n  \u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eVerifies ownership\u003c\/strong\u003e by re-reading the Data Table. If any level wasn’t claimed correctly, it \u003cstrong\u003erolls back partial claims\u003c\/strong\u003e and retries after a short wait.\u003c\/li\u003e\n\u003c\/ul\u003e\n\n\u003ch3\u003eUse cases\u003c\/h3\u003e\n\u003cul\u003e\n  \u003cli\u003ePrevent overlapping runs for operations scoped to \u003cem\u003etenant.resource\u003c\/em\u003e (e.g., \u003cem\u003eacme.sync\u003c\/em\u003e), ensuring only one workflow holds the lease.\u003c\/li\u003e\n  \u003cli\u003eRate-limit expensive API calls per hierarchical key (e.g., per \u003cem\u003eaccount\u003c\/em\u003e and \u003cem\u003eaccount.endpoint\u003c\/em\u003e).\u003c\/li\u003e\n  \u003cli\u003eBuild safe concurrency controls for SaaS automation pipelines where multiple workflows contend for the same namespace.\u003c\/li\u003e\n\u003c\/ul\u003e\n\n\u003ch3\u003eTechnical details\u003c\/h3\u003e\n\u003cul\u003e\n  \u003cli\u003e\n\u003cstrong\u003ePrimary storage:\u003c\/strong\u003e n8n Data Table (rows keyed by \u003ccode\u003emutex\u003c\/code\u003e).\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eConfigurable columns:\u003c\/strong\u003e \u003ccode\u003emutex\u003c\/code\u003e, \u003ccode\u003ecurrentToken\u003c\/code\u003e, \u003ccode\u003evalidUntil\u003c\/code\u003e, and optionally \u003ccode\u003erateMax\u003c\/code\u003e, \u003ccode\u003erateWindowSeconds\u003c\/code\u003e, \u003ccode\u003erateUsed\u003c\/code\u003e, \u003ccode\u003erateWindowStart\u003c\/code\u003e.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eWorkflow nodes used:\u003c\/strong\u003e \u003ccode\u003eif\u003c\/code\u003e, \u003ccode\u003eset\u003c\/code\u003e, \u003ccode\u003ecode\u003c\/code\u003e, \u003ccode\u003ewait\u003c\/code\u003e, \u003ccode\u003elimit\u003c\/code\u003e, and hierarchical \u003ccode\u003esplit\u003c\/code\u003e-out logic.\u003c\/li\u003e\n\u003c\/ul\u003e","brand":"N8N Commerce","offers":[{"title":"Default Title","offer_id":45761010106547,"sku":"N8N-17820","price":68.99,"currency_code":"GBP","in_stock":true}],"thumbnail_url":"\/\/cdn.shopify.com\/s\/files\/1\/0749\/6279\/6723\/files\/WVBwIiW_hQ3NraSWpFJm-_onQjb6J2.png?v=1785921208","url":"https:\/\/buyflowscripts.com\/products\/n8n-mutex-lease-tokens-for-hierarchical-namespaces-rate-limit","provider":"N8N Commerce","version":"1.0","type":"link"}