# What's the purpose of the Directory layer?

**URL:** <https://forums.foundationdb.org/t/whats-the-purpose-of-the-directory-layer/677>\
**Category:** FoundationDB Layers\
**Created:** [September 2, 2018, 8:58pm UTC](https://forums.foundationdb.org/t/whats-the-purpose-of-the-directory-layer/677 "2018-09-02T20:58:11Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![alloc](https://sea1.discourse-cdn.com/foundationdb/user_avatar/forums.foundationdb.org/alloc/32/9_2.png) [@alloc](https://forums.foundationdb.org/u/alloc)\
**Post date:** [September 8, 2018, 4:19pm UTC](https://forums.foundationdb.org/t/whats-the-purpose-of-the-directory-layer/677/4 "2018-09-08T16:19:22Z")

</div>

> [@amirouche](#):
>
> Does this translates in terms of Python code into creating `Directory` instance?

Yeah, creating the directory instance (i.e., calling `create`, `open`, or `create_or_open`). Listing the directory layer also queries it.

> [@amirouche](#):
>
> I just want to stress that `Subspace` alone already allows that.

Correct.

> [@amirouche](#):
>
> A “single usage” like say, in a mongodb-like collection, there is the 1) actual documents and 2) the description of indices (metadata) 3) the actual indices. All those three subspaces don’t need to be directories to me.

Yeah, that is loosely what I meant by a single “usage”, though there’s probably a better term for it. Though different collections might have their own directory (or different “database” where “database” is used to mean “a set of collections”.)

> [@amirouche](#):
>
> That said it’s a more ‘static’ approach, I can not dynamically in the application create subspaces since they are statically ‘allocated’ in the enums.

Your approach here looks solid enough to me. Depending on the application, you might be able to still create new subspaces on the fly (for certain definitions of “on the fly”). I’mg going to use your example of a document database with documents, indices, and meta-data about which indices exist. Lets say you wanted to add a new index. In the index meta-data, if you include the (short) subspace prefix, then you can effectively add to your enum on the fly. Now, um, you have to somehow solve the problem of how do you make sure all of your clients get word that the new index exists (but that [shouldn’t be too hard, right?](https://forums.foundationdb.org/t/implementing-atomic-ddl-for-sql-schema/678)), but once you do, you get the subspace prefix virtually for free.

But yeah, a static approach would sound reasonable if you have some notion of what the subspaces might look like _a priori_, which you probably do.

---

_[View the full topic](https://forums.foundationdb.org/t/whats-the-purpose-of-the-directory-layer/677)._
