<p>Assuming you’ve followed the <a href="https://craftcms.com/knowledge-base/configuring-load-balanced-environments" rel="nofollow noreferrer">knowledge base article</a> and have centralised resources such as sessions, mutex, caches, the database, and logs, it should be safe to run garbage collection once on any single web server.</p>
<p>If anything that needs to be garbage collected is stored on each individual web server then you’re likely going to have to run it once per server. Alternatively, you could create a custom module that performs garbage collection only on specific items to avoid redundant <code>gc</code> calls.</p>

CC BY-SA 4.0
2024-09-13T14:03:09.577Z
2024-09-13T14:03:09.577Z
Ben Croker
<p>Thanks Ben!</p>
<p>Here's an additional answer from Brad Bell (via Support), which I want to share with you as well:</p>
<p>Ben's answer is correct.</p>
<p>If everything is configured according to that article, all of Craft's native commands should just run on one node.</p>
<p>We have seen issues where people run a post-deploy console command that executes on every node, and that can actually cause some race conditions and subtle bugs depending on the command because the database is still a single point of resource contention.</p>
<p>So if you're in that post-deloy command scenario, you'll ideally want to ensure that post-deploy command only runs on one instance, as well.</p>

CC BY-SA 4.0
2024-09-16T07:41:01.980Z
2024-09-16T07:41:01.980Z
Matthias Redl-Mann
<p>We are running Craft in a load-balanced environment according to the docs: <a href="https://craftcms.com/knowledge-base/configuring-load-balanced-environments" rel="nofollow noreferrer">https://craftcms.com/knowledge-base/configuring-load-balanced-environments</a></p>
<p>Once daily we need to execute <code>craft gc/run</code> to keep the system clean.</p>
<p>My question: is this something which needs to be done on each web-node serving craft or is it only necessary to run it once regardless of the amount of nodes behind the load-balancer.</p>
<p>Background:</p>
<ul>
<li>If non-shared files are affected, it should run on all instances behind the LB</li>
<li>If only DB or Redis Caches are affected, we just run it once to avoid multiple executions</li>
</ul>

<console><load-balancer><garbage-collection>
Running `craft gc/run` in load-balanced environments
# Running `craft gc/run` in load-balanced environments

(Asked by: username_0 on 2024-09-13)

We are running Craft in a load-balanced environment according to the docs: <https://craftcms.com/knowledge-base/configuring-load-balanced-environments>

Once daily we need to execute `craft gc/run` to keep the system clean.

My question: is this something which needs to be done on each web-node serving craft or is it only necessary to run it once regardless of the amount of nodes behind the load-balancer.

Background:

* If non-shared files are affected, it should run on all instances behind the LB
* If only DB or Redis Caches are affected, we just run it once to avoid multiple executions

**Tags:** console, load-balancer, garbage-collection


---

## 2 answers

### Answer by username_1 on 2024-09-13. Score: 2 | Accepted answer

Assuming you’ve followed the [knowledge base article](https://craftcms.com/knowledge-base/configuring-load-balanced-environments) and have centralised resources such as sessions, mutex, caches, the database, and logs, it should be safe to run garbage collection once on any single web server.

If anything that needs to be garbage collected is stored on each individual web server then you’re likely going to have to run it once per server. Alternatively, you could create a custom module that performs garbage collection only on specific items to avoid redundant `gc` calls.


---

### Answer by username_0 on 2024-09-16. Score: 1

Thanks Ben!

Here's an additional answer from Brad Bell (via Support), which I want to share with you as well:

Ben's answer is correct.

If everything is configured according to that article, all of Craft's native commands should just run on one node.

We have seen issues where people run a post-deploy console command that executes on every node, and that can actually cause some race conditions and subtle bugs depending on the command because the database is still a single point of resource contention.

So if you're in that post-deloy command scenario, you'll ideally want to ensure that post-deploy command only runs on one instance, as well.


---

