Sitecore XC9, Data Isolation & Artifact Stores

Saturday, March 17, 2018

If you've installed XC9 and started to take a look into what gets installed, you should have by now noticed there there a number of different environments that get setup for you out of the box, these include:

  • HabitatAuthoring
  • HabitatShops
  • AdventureWorksAuthoring
  • AdventureWorksShops

Now what you'll see when you look into these environments is that HabitatShops & HabitatAuthoring both share the same catalog data, as do AdventureWorksAuthoring & AdventureWorksShops. This makes sense, you would want your shops role for your Habitat site to be accessing the same data that your Authoring role is, as you would with the Adventure Works site. But how does this work under the hood? Well this data isolation is achieved using Artifact Stores.

Artifact Stores

These allow you to provide a key that is used to store your data against, and you can then use that key in your environment definition to define which set of data the envinronment you're configuring is going to work against. This is important when you start to look into multi-shop or multi-tenancy installations as a lot of the time you would want to keep the commerce data for the different shops or tenants you're creating separate.

If you take a look into the json files for the environments that come included in XC9, you can see the ArtifactStoreId is one of the first properties declared, you can see an example of this in the HabitatAuthoring environment.

Now if you take a look in the HabitatShops environment it will have the same ArtifactStoreId value. Similarly if you take a look at the AdventureWorksAuthoring & AdventureWorksShops environments they will share a different ID to this one.

So that explains the concept, but how does this get reflected in the data stored in the database?

Data Storage

It took me a little bit to figure out how this data key was translated to the entities that are stored in the database. I originally started searching inside the JSON data for each of the entites but couldn't find it? It was then that I released that it was right under my nose all along!

SQL Structure

The value is stored against the EnvironmentId field above, meaning that all the entities that are shared between the Habitat environments have their ArtifactId value stored in that field, and the same for the AdventureWorks environments, and it will be the same for any custom environments that you create!

Composite Primary Key

If you look at the image above you will see the Primary Key on the table is actaully a Composite Primary Key consisting of both the EnvironmentId and the actual ID of the Entity itself. Now there is some debate about whether Composite Primary Keys are a good idea, but I'm not going to into that here. I will say however that in my opinion the non-relational structure of the XC databases does remove the importance of this arguement somewhat. What this does mean though is that you can have the same element with the exactly the same Id exist in two different Artifact Stores.

Yay for Flexbility!

comments powered by Disqus