# Cloud variable vs pub/sub

**URL:** <https://community.particle.io/t/cloud-variable-vs-pub-sub/41716>\
**Category:** General\
**Created:** [May 8, 2018, 11:00am UTC](https://community.particle.io/t/cloud-variable-vs-pub-sub/41716 "2018-05-08T11:00:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![netpex](https://avatars.discourse-cdn.com/v4/letter/n/22d042/32.png) [@netpex](https://community.particle.io/u/netpex)\
**Post date:** [May 8, 2018, 11:00am UTC](https://community.particle.io/t/cloud-variable-vs-pub-sub/41716/1 "2018-05-08T11:00:19Z")

</div>

Just curious what the advantage is between the two? Could someone (someone who feels they have time) just outline when one would use cloud variable and when one would use pub/sub?

I have a use case and I’m wondering if it might be suited to cloud variable more than pub/sub but I’m not sure why…

I’d like to have a physical toggle switch which I could toggle when I want all my devices to stop issuing audible notifications. I THINK it would be more sensible for this toggle to update a cloud variable than it would to send a publish but being a bit new to all this I can’t really articulate WHY I think cloud variable seems to make more sense to me. And maybe it shouldn’t!

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [May 8, 2018, 11:34am UTC](https://community.particle.io/t/cloud-variable-vs-pub-sub/41716/2 "2018-05-08T11:34:35Z")

</div>

`Particle.variables()` can be altered in your code numerous times without ever causing any network traffic, only when someone _requests_ the current value, the value is transmitted to the cloud. So this is always an action that’s initiated from the cloud side and never from the device side. The value is _only_ stored in the device and _never_ in the cloud.  
`Particle.publish()` _pushes_ an event into the cloud, so that’s always initiated by the device and not by the cloud.  
`Particle.subscribe()` “reacts” to an event from the cloud - which could have been pushed from the same device or another or even from any other source that can publish Particle events.
