Upon uploading code to App Service, the new version becomes instantly accessible, as seen when we deployed our code and promptly navigated through it using the App Service default domain. 

 

However, at times we wish to evaluate the version prior to its release to ensure its functionality is accurate before external users may access it. Consequently, we utilize deployment slots.

 

Deployment slots facilitate the uploading of code.then evaluate it independently from the main/production location. Subsequent to validation,we swap the slots and promote it to production,

 

How and when these slots can be created

  • New slots are create via the portal. The quantity of permitted slots is depends upon the plan. Standard Plan for example, permit a maximum of 5 slots.
  • In plans lower to the standard, for instance, the fee, the shared, or the basic, do not have slots at all.

 

 

How Slots works in Azure

A slot is basically a fully functional app service with its own URL which can be used it, in order to access the slot specifically and see how the code looks before swapping it for the main URL of the app service.

Cost: slots are free. They do not incur additional cost in addition to the app service cost itself.

 

 

Features of Slots

Traffic splitting- This indicates that traffic can be distributed among slots, resulting in some users being directed to the production site or production slot, while others are routed to the new slot.

For instance, you wish to implement the code incrementally. first, quite a minor proportion of the users Will access the newly launched website. Based on their feedback, You will ascertain your ability to create the new version. available to all users.

 

Define Slot in App Service
Go to App service detail page

 

By default a single slot already present there 

  • Production - 100%  - Running
  • Which makes sense since currently this is the only slot

 

Add one more slot

  • Click add slot at top
  • Click Add
  • A slot is added 
  • Click this newly added slot
    • This slot is basically a fully functional app service with its own default domain right here.
    • Slot URL: -
    • Click Default Domain link of that slot
      • you can see, the default placeholder of the application service signifies this position. Furthermore, observe the URL that we are presently examining.
      • https://deepak-web-ecommerc-staging.azurewebsites.net/
        • So this slot is currently waiting for a code to be deployed to it.
  • Traffic Distribution/ Traffic Splitting
    • 0 at staging

 

 

Deploy code to new Slot ‘Staging’
Go to your code locally in vs code , Azure Extension tab, we can see our slot

Make some change in your code 
Check you change at local using F5

Deploy directory to slot, by right click your slot name and click Deploy to slot

Confirm deploy in confirmation box 

Click “Browse website”

Url now point to staging with changes - https://deepak-web-ecommerc-staging.azurewebsites.net/

you can see your old production version at https://deepak-web-ecommerc.azurewebsites.net/ 


SPLIT TRAFFIC BETWEEN SLOTS

 

Currently traffic split as

Currently all traffic that reaches the default domain of the app service is routed to the production slot and the none is routed to the staging slot

 

Let assign Traffic to Staging / redirect 50% traffic to staging as well

We define that half of the traffic for the main app service will be routed to the production slot and half will go to the staging slot.

 

Go to Url https://deepak-web-ecommerc.azurewebsites.net/  and hit refresh
Remove  cookies to make you as additional user and see changes / open in go to incognito mode.

 

 

SWAP our Slots
To make our stating the production version after testing

first allocate 0 to stating, so that no user can see the newer version

 

Click Swap button at top

 

A pop up window will open

Click Swap in pop up window

 

Refresh both production and stating URLs. we can see 

  • Our staging changes at Production now. 
  • Production backup at our stating now. the staging slot now shows us what was the production code

 


Related Question