Skip to main content

Posts

Showing posts from July, 2020

Use Azure App Configuration To Store Hierarchical Data

.NET Core has first class support for parsing hierarchical configuration data. If you have a JSON configuration like this, 
{ "rootObject": [ { "level1": "l1v1", "level2": "l1v2" }, { "level1": "l2v1", "level2": "l2v2" } ] }
then you can easily target individual values with "rootObject:[0]:level1". However to store this JSON, you have to either use a File System or some kind of database. The problem with this approach is that you have to modify the entire document when you want to change a value of any field. If you are not careful, you may end up corrupting the JSON and thus breaking your system.
This is where Azure App Configuration comes in the picture. Azure App Configuration is nothing but a key-value store. We can use that to store the hierarchical values like this:

CPU Cycles Are Cheap!

Modern CPUs have gotten so ridiculously fast that for most business applications we don't need to worry about optimizing the code we are writing. On the other hand, network calls like getting a record from database consume an eternity of CPU cycles. For example consider the following code example:
foreach (var item in itemList) {     var data = MakeANetworkCallToDatabaseAndGetData(item.Id);     Process(data); }
On the face of it, there is nothing wrong with this. The code works and even performs fine when the items in the list are less. But you will start to see things slow down when the item list grows. So how to solve this problem?
var allIds = itemList.Select(x => x.Id).ToList(); var dataList = MakeANetworkCallToDatabaseAndGetData(allIds); foreach (var data in dataList) {    Process(data); } As you can see in above code, we have reduced the network call to just one and process it once we have everything in memory. Things are much faster now!
Obviously, this does not apply to all situati…