Build a highly available app in Node.js with RA-GRS storage
This sample shows how to use the Node.js V10 Storage SDK with read-access geo-redundant storage (RA-GRS) to create a highly available app that accesses files from secondary storage when primary storage is down, and then switches back to primary storage when it becomes available again. For more information, see Designing HA Apps with RA-GRS storage.
If you don't have a Microsoft Azure subscription, you can get a free account here.
In this sample, you will find the following folders:
- storage-node-ha-ra-grs-v10 - references Storage Blob SDK v10.3.0
- storage-node-ha-ra-grs-v12 - references Storage Blob SDK v12.0.0
Following prerequisites are needed to run this sample and verify that files are downloaded from primary storage:
Add your storage account credentials to the
.env.examplefile and then rename it to
You can find this information in the Azure portal by navigating to your storage account and selecting Access keys in the Settings section.
Install the required dependencies in the console window by running
Steps to test secondary storage access:
Open a command prompt with administrator privileges.
Get the IP address of your storage account primary endpoint domain by entering the following command, replacing
STORAGEACCOUNTNAMEwith the name of your storage account.
Get the IP address of your local host by entering
ifconfigon Linux or
Add an invalid static route for a destination host. Replace
<DestinationIp>with your storage account IP address, and
<GatewayIp>with your local host IP address.
route add <DestinationIp> gw <GatewayIp>
route add <DestinationIp> <GatewayIp>
In this sample you will do the following:
- Create a storage account.
- Create a container.
- Upload a file to blockblob.
- Enter D to download the file or Q to quit.
How it works
This sample creates a new container in blob storage and uploads a sample file into it called
HelloWorld.jpg. It then checks secondary storage repeatedly until both the container and file have been replicated. The user can then enter D to download the file or Q to quit. If the file is successfully downloaded, the sample indicates whether it came from primary or secondary storage. When the user quits the sample, it deletes the container and file.
How to run the sample
To run this sample and verify that files are downloaded from primary storage, we are going to:
Launch the sample from the console window by running
Wait until the sample reports that the container and file have replicated to secondary storage.
When prompted, press D to download the sample file and verify that it comes from primary storage.
To test secondary storage access, we are going to:
In the console window with the running sample, press D to download the sample file and verify that it comes from secondary storage.
Remove the invalid static route.
route del <DestinationIp> gw <GatewayIp>
route delete <DestinationIp>
In the console window with the running sample, press D to download the sample file and verify that it comes from primary storage.
Press Q to quit the sample and delete the container and file from storage.