Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure Auto Scaling with a Singleton Class

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?

like image 356
BattleRush Avatar asked Jan 31 '26 12:01

BattleRush


1 Answers

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.

like image 68
markti Avatar answered Feb 03 '26 04:02

markti