[{"data":1,"prerenderedAt":391},["Reactive",2],{"navigation":3,"/other/workers-and-background-tasks":118,"/other/workers-and-background-tasks-surround":388},[4,14,43,83,99],{"title":5,"_path":6,"children":7},"Welcome","/welcome",[8,11],{"title":9,"_path":10},"Feature List","/welcome/feature-list",{"title":12,"_path":13},"FAQs","/welcome/faqs",{"title":15,"_path":16,"children":17},"Getting Started","/getting-started",[18,19,22,25,28,31,34,37,40],{"title":15,"_path":16},{"title":20,"_path":21},"Pre-requisites","/getting-started/prerequisites",{"title":23,"_path":24},"Installation","/getting-started/installation",{"title":26,"_path":27},"Upgrading","/getting-started/upgrading",{"title":29,"_path":30},"Configuration","/getting-started/configuration",{"title":32,"_path":33},"DNS configuration","/getting-started/dns-configuration",{"title":35,"_path":36},"Upgrading to v3","/getting-started/upgrade-to-v3",{"title":38,"_path":39},"Upgrading to v2","/getting-started/upgrade-to-v2",{"title":41,"_path":42},"The postal command","/getting-started/postal-command",{"title":44,"_path":45,"children":46},"Features","/features",[47,50,53,56,59,62,65,68,71,74,77,80],{"title":48,"_path":49},"Click & Open Tracking","/features/click-and-open-tracking",{"title":51,"_path":52},"Health & Metrics","/features/health-metrics",{"title":54,"_path":55},"IP Pools","/features/ip-pools",{"title":57,"_path":58},"Logging","/features/logging",{"title":60,"_path":61},"Mail Server Settings","/features/mail-server-settings",{"title":63,"_path":64},"OpenID Connect","/features/oidc",{"title":66,"_path":67},"Routing Incoming E-Mail","/features/routing-incoming-email",{"title":69,"_path":70},"Sending Domains","/features/sending-domains",{"title":72,"_path":73},"SMTP Authentication","/features/smtp-authentication",{"title":75,"_path":76},"SMTP TLS","/features/smtp-tls",{"title":78,"_path":79},"Spam & Virus Checking","/features/spam-and-virus-checking",{"title":81,"_path":82},"Users & Permissions","/features/users-and-permissions",{"title":84,"_path":85,"children":86},"Developer","/developer",[87,90,93,96],{"title":88,"_path":89},"Using the API","/developer/api",{"title":91,"_path":92},"Client Libraries","/developer/client-libraries",{"title":94,"_path":95},"Receiving e-mail by HTTP","/developer/http-payloads",{"title":97,"_path":98},"Webhooks","/developer/webhooks",{"title":100,"_path":101,"children":102},"Other Notes","/other",[103,106,109,112,115],{"title":104,"_path":105},"Auto-Responders & Bounces","/other/auto-responders-and-bounces",{"title":107,"_path":108},"Our container image","/other/containers",{"title":110,"_path":111},"Debugging","/other/debugging",{"title":113,"_path":114},"Wildcards & Address Tags","/other/wildcards-and-address-tags",{"title":116,"_path":117},"Workers & Background Tasks","/other/workers-and-background-tasks",{"_path":117,"_dir":119,"_draft":120,"_partial":120,"_locale":121,"title":116,"description":122,"body":123,"_type":383,"_id":384,"_source":385,"_file":386,"_extension":387},"other",false,"","What Postal workers do and how to scale them.",{"type":124,"children":125,"toc":377},"root",[126,151,156,163,184,239,252,264,270,283,289],{"type":127,"tag":128,"props":129,"children":130},"element","p",{},[131,134,140,142,149],{"type":132,"value":133},"text","All mail processing in Postal happens in ",{"type":127,"tag":135,"props":136,"children":137},"strong",{},[138],{"type":132,"value":139},"worker",{"type":132,"value":141}," processes (",{"type":127,"tag":143,"props":144,"children":146},"code",{"className":145},[],[147],{"type":132,"value":148},"postal worker",{"type":132,"value":150},"). The web and SMTP servers only accept messages and place them on a queue in the main database; workers take them from the queue, deliver them, and run housekeeping tasks. Since Postal v3 there is no message broker - workers coordinate purely through the database.",{"type":127,"tag":128,"props":152,"children":153},{},[154],{"type":132,"value":155},"You can run as many worker processes as you need, on as many hosts as you need, provided they all share the same database.",{"type":127,"tag":157,"props":158,"children":160},"h2",{"id":159},"what-workers-do",[161],{"type":132,"value":162},"What workers do",{"type":127,"tag":128,"props":164,"children":165},{},[166,168,174,176,182],{"type":132,"value":167},"Each worker runs a number of threads (set by ",{"type":127,"tag":143,"props":169,"children":171},{"className":170},[],[172],{"type":132,"value":173},"worker.threads",{"type":132,"value":175},", default ",{"type":127,"tag":143,"props":177,"children":179},{"className":178},[],[180],{"type":132,"value":181},"2",{"type":132,"value":183},") which repeatedly take the next ready message or webhook request from the queue and process it:",{"type":127,"tag":185,"props":186,"children":187},"ul",{},[188,207,224],{"type":127,"tag":189,"props":190,"children":191},"li",{},[192,197,199,205],{"type":127,"tag":135,"props":193,"children":194},{},[195],{"type":132,"value":196},"Outgoing",{"type":132,"value":198}," messages are checked against the server's ",{"type":127,"tag":200,"props":201,"children":202},"a",{"href":61},[203],{"type":132,"value":204},"settings",{"type":132,"value":206}," (suspension, send limit, credential hold, suppression list and development mode), optionally inspected for spam, prepared for click/open tracking, DKIM signed and delivered by SMTP to the recipient's mail server (or your configured relays).",{"type":127,"tag":189,"props":208,"children":209},{},[210,215,217,222],{"type":127,"tag":135,"props":211,"children":212},{},[213],{"type":132,"value":214},"Incoming",{"type":132,"value":216}," messages are inspected for spam and delivered according to their ",{"type":127,"tag":200,"props":218,"children":219},{"href":67},[220],{"type":132,"value":221},"route",{"type":132,"value":223},".",{"type":127,"tag":189,"props":225,"children":226},{},[227,232,234,238],{"type":127,"tag":135,"props":228,"children":229},{},[230],{"type":132,"value":231},"Webhook requests",{"type":132,"value":233}," are delivered to your endpoints. See ",{"type":127,"tag":200,"props":235,"children":236},{"href":98},[237],{"type":132,"value":97},{"type":132,"value":223},{"type":127,"tag":128,"props":240,"children":241},{},[242,244,250],{"type":132,"value":243},"Messages which fail temporarily are retried with an increasing back-off up to ",{"type":127,"tag":143,"props":245,"children":247},{"className":246},[],[248],{"type":132,"value":249},"postal.default_maximum_delivery_attempts",{"type":132,"value":251}," times (default 18, roughly 31 hours) before being hard failed. Messages for the same destination are batched onto a single connection where possible.",{"type":127,"tag":128,"props":253,"children":254},{},[255,257,262],{"type":132,"value":256},"When ",{"type":127,"tag":200,"props":258,"children":259},{"href":55},[260],{"type":132,"value":261},"IP pools",{"type":132,"value":263}," are in use, a message allocated to an IP address is only processed by a worker running on a host that has that address.",{"type":127,"tag":157,"props":265,"children":267},{"id":266},"housekeeping-tasks",[268],{"type":132,"value":269},"Housekeeping tasks",{"type":127,"tag":128,"props":271,"children":272},{},[273,275,281],{"type":132,"value":274},"Workers also run periodic maintenance, such as re-checking domain DNS records, applying ",{"type":127,"tag":200,"props":276,"children":278},{"href":277},"/features/mail-server-settings#retention",[279],{"type":132,"value":280},"retention settings",{"type":132,"value":282},", expiring held messages, pruning suppression lists and webhook history, and removing servers and organizations that have been deleted. Workers elect one of themselves to run these tasks so that each runs only once regardless of how many workers you have; if that worker stops, another takes over automatically.",{"type":127,"tag":157,"props":284,"children":286},{"id":285},"scaling-and-restarting",[287],{"type":132,"value":288},"Scaling and restarting",{"type":127,"tag":185,"props":290,"children":291},{},[292,327,340],{"type":127,"tag":189,"props":293,"children":294},{},[295,297,302,304,310,312,318,320,325],{"type":132,"value":296},"To handle more mail, increase ",{"type":127,"tag":143,"props":298,"children":300},{"className":299},[],[301],{"type":132,"value":173},{"type":132,"value":303}," and/or run more worker processes (see ",{"type":127,"tag":200,"props":305,"children":307},{"href":306},"/getting-started/postal-command#number-of-workers",[308],{"type":132,"value":309},"the postal command",{"type":132,"value":311}," for the standard installation). The ",{"type":127,"tag":143,"props":313,"children":315},{"className":314},[],[316],{"type":132,"value":317},"postal_message_queue_latency",{"type":132,"value":319}," ",{"type":127,"tag":200,"props":321,"children":322},{"href":52},[323],{"type":132,"value":324},"metric",{"type":132,"value":326}," shows how long messages are waiting to be picked up.",{"type":127,"tag":189,"props":328,"children":329},{},[330,332,338],{"type":132,"value":331},"Each worker holds a handful of database connections per thread, so size MariaDB's ",{"type":127,"tag":143,"props":333,"children":335},{"className":334},[],[336],{"type":132,"value":337},"max_connections",{"type":132,"value":339}," accordingly when adding workers.",{"type":127,"tag":189,"props":341,"children":342},{},[343,345,351,353,359,361,367,369,375],{"type":132,"value":344},"Workers can be restarted safely with ",{"type":127,"tag":143,"props":346,"children":348},{"className":347},[],[349],{"type":132,"value":350},"SIGTERM",{"type":132,"value":352}," (which ",{"type":127,"tag":143,"props":354,"children":356},{"className":355},[],[357],{"type":132,"value":358},"docker stop",{"type":132,"value":360}," sends): they finish the message they are processing before exiting. If a worker is killed abruptly, any message it was processing stays locked and is removed from the queue by a housekeeping task after ",{"type":127,"tag":143,"props":362,"children":364},{"className":363},[],[365],{"type":132,"value":366},"postal.queued_message_lock_stale_days",{"type":132,"value":368}," (default 1 day) rather than retried, so avoid ",{"type":127,"tag":143,"props":370,"children":372},{"className":371},[],[373],{"type":132,"value":374},"SIGKILL",{"type":132,"value":376}," where possible.",{"title":121,"searchDepth":378,"depth":378,"links":379},2,[380,381,382],{"id":159,"depth":378,"text":162},{"id":266,"depth":378,"text":269},{"id":285,"depth":378,"text":288},"markdown","content:5.other:5.workers-and-background-tasks.md","content","5.other/5.workers-and-background-tasks.md","md",[389,390],{"_path":114,"title":113,"description":121},null,1789749433858]