Azure has this setting that you can Auto Scale running Instances of your Web app depending how big the current load is.
My question is what happens if you have a Singleton Class and run Multiple Instances, will this class exist once per Instance? From my understating each Instance will have the Singleton Class initialized, is this correct?
Each 'instance' is really just another virtual machine running your web app. Hence, each will have its own application pool, memory space, and IIS worker process handling its traffic for your web app.
Since a singleton runs in its own application space on each of these instances (VMs) you will get one singleton for each 'instance'.
If you are interested in creating instances of objects that transcend their memory location check out the Actor Pattern, project Orleans and the new Azure Service Fabric. These technologies are implementations of the Actor pattern and allow you to create an object that is agnostic to the physical infrastructure it runs on.
If you are just interested in sharing state between multiple instances of your web app, check out Redis cache as a high performant way to create a shared pool of data between web apps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With