A Neglected Serverless Data Store: Cloud Directory
Curious as to what AWS Cloud Directory has to offer in terms of a serverless data store? Then read on for some details.
Join the DZone community and get the full member experience.Join For Free
Lately, I’ve been having lots of fun with Amazon Cloud Directory. Three months before, Cloud Directory was all new to me. Today, I am convinced that Cloud Directory is a neglected serverless data store that deserves much more attention. Let me explain what Cloud Directory is and why it is an excellent choice in serverless architectures.
A Short Introduction to Cloud Directory
Cloud Directory is a fully managed, hierarchical data store on AWS. Let’s talk about hierarchical data first.
Introducing Hierarchical Data and Cloud Directory Terminology
In this post, I model a Slack-like chat system using a hierarchical data model. There are two teams. Team Widdix use the general channel to discuss work-related topics, and they discuss AWS announcements in the news channel. The AWS team is busy planning re:Invent in the re:Invent channel, and they use the general channel to discuss other topics. The following figure shows the chat system data hierarchy.
In Cloud Directory, a Directory always comes with an implicit single Root Node object. When you create a Node object, you have to specify the parent (Root Node object or Node object). Every Node object has exactly one parent, and a Child Link is automatically created for you. Therefore, every Node object has
Accessing a Node
You can access a Node object in the Directory with a Selector that can be a Cloud Directory generated Object Identifier or a Path that you can control. The Selector is a string where the first character is important.
- Selectors that start with a
$point to an Object Identifier, e.g.,
$287d. The value is generated by Cloud Directory when you create an object.
- Selectors that start with a
/point to a Path, e.g.,
/aws/general. The path is a concatenation of the Child Link's Link Name.
Let’s look at the Path more closely. As you already learned, when you create a Node, a Child Link is automatically created for you that points to the parent. The Child Link has a Link Name that you have to supply, and it must be unique for all nodes sharing the same parent. The following figure shows the Link Names and Object Identifiers of the chat system.
/widdix/general uniquely identifies the general channel of team Widdix while the path
/aws/general uniquely identifies the general channel of team AWS. The Link Name
general can be used multiple times in the Directory but not for the same parent.
For each Node, you can get:
- children (
[0..N]children for a Node)
- parents (always a single parent for a Node)
- paths to Root Node (always a single path for a Node)
Storing Data Based on a Schema
So far, I have not talked about the ability to store data besides the hierarchy. This changes now. A Facet defines a collection of Attributes. Compared to the relational database world, you can think of a Facet as a table and an Attribute as a column for now. An Attribute is defined by:
- type (
- required or optional
- mutable or immutable
- default value
- validation rules
- String length
- Binary length
- String from set
- Number comparison
A Node can be associated with one or many Facets. The following figure shows the Facets of the chat system (each Node is associated only with a single Facet).
A Schema is a collection of Facets. Schemas are a bit tricky. When you create a new Schema, this is called a Development Schema, and you can modify it (create facets, change facets, delete facets). When you are happy with the Development Schema, you can publish it, and a Published Schema is created for you that is versioned. The Published Schema cannot be changed. It can only be upgraded in a backward compatible way (add a facet, add an optional attribute to an existing facet). When you create a Directory, you have to select a Published Schema which is then copied and becomes an Applied Schema. The Applied Schema can also be upgraded in a backward compatible way. The following table summaries the different types of Schemas.
|Schema type||Mutable||Versioned||Backward compatible Upgrade|
You can now store a hierarchy together with attributes. Let’s look at one more feature: linking nodes.
Linking Nodes: Typed Links
Besides the Child Link, Cloud Directory supports a Typed Link that goes from one Node to another Node. The cool thing about the Typed Link is that you can attach Attributes to it as well defined in a Typed Link Facet. Some (or all) of the Attributes are used as the identity of the Typed Link.
You can not use a Path to navigate with Typed Links.
The following figure shows how a Typed Link can be used in the chat system to share channels between teams. The AWS team now has access to the news channel of the Widdix team, and it appears as Widdix-news in the AWS team.
For each Node, you can get:
That is the end of the short introduction to Cloud Directory. Let’s look at how Cloud Directory fits into the serverless space next.
How Does Cloud Directory Fit into the Serverless Space?
Cloud Directory is truly serverless. There is zero configuration.
- Cloud Directory requires no management of machines or software
- You pay per request and used storage
- Scales automatically
- Is fault tolerant/highly available
Cloud Directory can be used from Lamba with the AWS SDK.
Besides the features you learned about so far, Cloud Directory also has support for:
- Multiple consistency levels
- Policies with efficient retrieval
- Leaf nodes (can have
Missing features: No backup/restore capability and no visual explorer of your directory.
If you use Cognito or Organizations, your data is already stored in Cloud Directory under the covers. Cloud Directory is a serverless hierarchical data store on AWS. It is a niche service that deserves more attention because it is easy to operate (zero configuration) and comes with transactional support. If you are interested in further Cloud Directory posts, subscribe to our RSS feed or Newsletter.
Thanks to Thorsten Höger for reviewing this article.
Published at DZone with permission of Michael Wittig. See the original article here.
Opinions expressed by DZone contributors are their own.