title: Google Cloud Functions how to detect number of active instances?
body: <p>I want to create a cloud function with EXACT 1 INSTANCE ALWAYS...</p>
  
  <p>I dont mind if some users get http 429, 500 or any crazy error code. But I do want to have always max one function online.</p>
  
  <p>Google says that case functions tryes to escaolanate over the max-instances it will throw http 429 to the user... but that is FALSE. </p>
  
  <p>I've doing plent of tests and always it get escalonate up when it reaches some request peak.... So since google ins't able to manage their own created parameters i would like to do by myself.</p>
  
  <p>Is there any way i can get the number of active instances of a specific cloud function? this way i can check if the instance is higher than 1 and drop all requests bymyself</p>
  
  <p>=================UPDATE==================</p>
  
  <p>I've been asked why I want to ensure only single instance... Usually I dont comment archtecture decisions but i will try explain this one.</p>
  
  <p>I don't like the way Firebase Realtime Database handle transactions, is inneficient and might lead to an unnecessary traffic. I've other questions here regarding this topic  <a href="https://stackoverflow.com/questions/60684968/android-firebase-transaction-having-a-simple-counter-problem">Android Firebase transaction having a simple counter problem</a> and due this problem I thought is much easier use Cloud Functions as a State aware backeend (although I know it was clearly desingned to not be)</p>
  
  <p>So I create a function that during warm up loads a branch from firebase with few nodes (each node being a counter) into a field...<br>
  Everytime a client needs to touch one of the counters it will call my function and, as it is loaded in memory and single threaded, the function will do atomically it and return <code>http 200</code> (as simple and fast as possible)...<br>
  My client was built to the possibility of receiving a <code>http 429</code> in which case it will wait a random amount of time and retry (untill sucess)  </p>
  
  <p>From time to time the function will synchronize with the database just to garantee things are fine. And as the function is now the only entity touching this branch of the database it is garanted to be incorrupt</p>
  
  <p>I've deployed this function a few days ago and according to the dashboard it takes 100ms to reply with the peak of 600ms. so it is absolutelly fine for my standards, BUUUUUUT google is automatically scalonating it to peak of 5 instances... what breaks the integrity of the counters.</p>