# Batch environment variables changes

**URL:** <https://forums.balena.io/t/batch-environment-variables-changes/1006>\
**Category:** Product support\
**Created:** [May 25, 2017, 7:57am UTC](https://forums.balena.io/t/batch-environment-variables-changes/1006 "2017-05-25T07:57:42Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![charlietango592](https://avatars.discourse-cdn.com/v4/letter/c/46a35a/32.png) [@charlietango592](https://forums.balena.io/u/charlietango592)\
**Post date:** [May 25, 2017, 7:57am UTC](https://forums.balena.io/t/batch-environment-variables-changes/1006/1 "2017-05-25T07:57:42Z")

</div>

Hey guys,

I’m curious if there is any known way to batch multiple environment variables changes, via the API/node-sdk, to avoid multiple device restarts.

Thanks very much!

---

<div class="post-metadata">

**Author:** ![imrehg](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/imrehg/32/36_2.png) [@imrehg](https://forums.balena.io/u/imrehg)\
**Post date:** [May 25, 2017, 9:12pm UTC](https://forums.balena.io/t/batch-environment-variables-changes/1006/2 "2017-05-25T21:12:45Z")

</div>

Hi, the API does do some batching, it doesn’t apply the changes right away, but after every update, it waits for a couple of seconds to see if there’s anything new coming in, and only after things stopped coming in it restarts the application. 🕰

I’ve tested it out by creating 10x new environment variables with 1s delay between them in the node SDK, and I only got a single application restart, a few seconds after the last environment variable creation call. So it’s definitely workable in this simple case.

How are you trying to update the env vars, can you tell us more about your situation and the issue you run into?

---

<div class="post-metadata">

**Author:** ![charlietango592](https://avatars.discourse-cdn.com/v4/letter/c/46a35a/32.png) [@charlietango592](https://forums.balena.io/u/charlietango592)\
**Post date:** [May 26, 2017, 8:12am UTC](https://forums.balena.io/t/batch-environment-variables-changes/1006/3 "2017-05-26T08:12:46Z")

</div>

Thanks for your answer!  
It sounds like a cool feature! In the app I’m working on, users can manage(add/update/remove) env vars for a device/application so I can’t be sure how much time will be between operations, because it’s at user’s will. This is what I’m facing 🙂 The simplest solution we could think of is to send all promises at once.

---

<div class="post-metadata">

**Author:** ![imrehg](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/imrehg/32/36_2.png) [@imrehg](https://forums.balena.io/u/imrehg)\
**Post date:** [May 26, 2017, 2:04pm UTC](https://forums.balena.io/t/batch-environment-variables-changes/1006/4 "2017-05-26T14:04:02Z")

</div>

Yeah, it sounds like if it’s based on user actions, you might want to do some caching on your side. It’s really a trade off between being timely and being efficient. 🏃‍♂️

🤔 Or maybe it can be that on your side you have a different user experience for env vars: in the dashboard when one var is saved it is immediately applied. IN your case, I think it could be cool to have users adding env vars, but then explicitly “commit” or “save” those changes, and then you’d submit them as one series… Just a thought 🙂

---

<div class="post-metadata">

**Author:** ![charlietango592](https://avatars.discourse-cdn.com/v4/letter/c/46a35a/32.png) [@charlietango592](https://forums.balena.io/u/charlietango592)\
**Post date:** [May 29, 2017, 1:42pm UTC](https://forums.balena.io/t/batch-environment-variables-changes/1006/5 "2017-05-29T13:42:40Z")

</div>

Thanks for suggestions 🙂

---

<div class="post-metadata">

**Author:** ![mhe\_lorenz](https://avatars.discourse-cdn.com/v4/letter/m/ba8739/32.png) [@mhe\_lorenz](https://forums.balena.io/u/mhe_lorenz)\
**Post date:** [September 9, 2019, 1:27pm UTC](https://forums.balena.io/t/batch-environment-variables-changes/1006/6 "2019-09-09T13:27:20Z")

</div>

I am working with a similar problem at the moment and the batching sounds promising for our use case. Are the answers given above still valid or do you have anything to add that have changed in the past two years @imrehg?

---

<div class="post-metadata">

**Author:** ![xginn8](https://avatars.discourse-cdn.com/v4/letter/x/8baadc/32.png) [@xginn8](https://forums.balena.io/u/xginn8)\
**Post date:** [September 9, 2019, 5:43pm UTC](https://forums.balena.io/t/batch-environment-variables-changes/1006/10 "2019-09-09T17:43:03Z")

</div>

Hi there @mhe_lorenz,

I’ve just tested this again, and if you are using a parallelized request (via the SDK) you _most likely_ will have the update applied in batch, though there are no guarantees to that batching behavior. For example, running parallelized requests like a `Promise.map()` from the node SDK limited the number of container restarts to a single restart, but a bash loop using a `sleep 1` and the balenaCLI caused three separate container restarts. I have opened an internal issue to discuss this behavior further, and we will update you if we decide to change that!
