1

I have a SQL Database in Azure. An S0 instance with 10 DTUs. This is enough 95% of the time.

However, when the App Service plan scales out (can go up to 20x in rare cases), I need 200/400 DTUs. Since this will not happen very often, so it would be a waste to always pay for these sizes. Is there a way to scale out the database when the app service scales out?

Thank you!

Joel'-'
  • 163
  • 5

1 Answers1

3

There's no direct way to have a DB scale up when a Web App does, but there is a workaround. You can have the scale up action on the web app trigger a webhook, so you can have that call either Azure Automation or an Azure Function, which then talks to the ARM API to scale up or down your SQL DB.

See here to see how to trigger a webhook on scaling.

Sam Cogan
  • 38,736
  • 6
  • 78
  • 114
  • Thank you very much. Ill try to do so. Let's hope I wont accidentally scale out my database to something really really expensive ;) – Joel'-' Sep 29 '18 at 20:37
  • Make sure you add checks to your script that prevents this – Sam Cogan Sep 30 '18 at 17:29
  • So i gave it a try. When upscaling the database, the application refuses to connect for a short while. System.Data.Entity.Core.EntityException: The underlying provider failed on Open. ---> System.Data.Entity.Core.EntityException: An exception has been raised that is likely due to a transient failure. If you are connecting to a SQL Azure database consider using SqlAzureExecutionStrategy. ---> System.Data.SqlClient.SqlException: Database 'xxx' on server 'xxx' is not currently available. Please retry the connection later. If the problem persists, contact customer support, and provide them th... – Joel'-' Oct 01 '18 at 19:04
  • 1
    Correct, there will be a brief period where no new connections will be allowed, you need to build your application to handle this if you want to scale – Sam Cogan Oct 01 '18 at 19:05
  • Is there an easy way to do this? Like "SqlAzureExecutionStrategy"? Or should I really queue my queries until the db is reachable again? – Joel'-' Oct 01 '18 at 19:29
  • At a basic level you could just build in retry logic, but yes you could also look at sqlAzureExecutionStrategy – Sam Cogan Oct 01 '18 at 19:37