# How does FoundationDB store keys with duplicate prefixes?

**URL:** <https://forums.foundationdb.org/t/how-does-foundationdb-store-keys-with-duplicate-prefixes/1234>\
**Category:** Using FoundationDB\
**Created:** [March 16, 2019, 3:26am UTC](https://forums.foundationdb.org/t/how-does-foundationdb-store-keys-with-duplicate-prefixes/1234 "2019-03-16T03:26:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jonahwest](https://avatars.discourse-cdn.com/v4/letter/j/90db22/32.png) [@jonahwest](https://forums.foundationdb.org/u/jonahwest)\
**Post date:** [March 16, 2019, 3:26am UTC](https://forums.foundationdb.org/t/how-does-foundationdb-store-keys-with-duplicate-prefixes/1234/1 "2019-03-16T03:26:49Z")

</div>

According to the documentation:

> keys starting with `'mytable\'` are sorted together (e.g. `'mytable\row1'` , `'mytable\row2'` , …)

**Does this mean that a prefix such as** `mytable` **will only be stored once?**

For example, if I had 500 keys that all started with `mytable`, would `mytable` be stored for all 500 keys, or would it be stored for the first key beginning with `mytable`, and have subsequent keys just reference the first `mytable`?

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![alexmiller](https://sea1.discourse-cdn.com/foundationdb/user_avatar/forums.foundationdb.org/alexmiller/32/326_2.png) [@alexmiller](https://forums.foundationdb.org/u/alexmiller)\
**Post date:** [March 16, 2019, 3:49am UTC](https://forums.foundationdb.org/t/how-does-foundationdb-store-keys-with-duplicate-prefixes/1234/2 "2019-03-16T03:49:22Z")

</div>

No, the `mytable\` prefix will be stored 500 times. The directory layer offers a way to reduce `mytable\` down to a smaller prefix, at the cost of an extra read.

The feature you’re looking for is called “prefix compression”. It’s being actively worked on as part of a new storage engine called [Redwood](https://www.youtube.com/watch?v=nlus1Z7TVTI). Eventually, it will come to replace the `ssd` storage engine, so you’ll get prefix compression by default, but it will still take some time for the development to reach that point.

---

<div class="post-metadata">

**Author:** ![jonahwest](https://avatars.discourse-cdn.com/v4/letter/j/90db22/32.png) [@jonahwest](https://forums.foundationdb.org/u/jonahwest)\
**Post date:** [March 16, 2019, 6:56am UTC](https://forums.foundationdb.org/t/how-does-foundationdb-store-keys-with-duplicate-prefixes/1234/3 "2019-03-16T06:56:47Z")

</div>

@alexmiller Thanks for the help! I have a few questions:

1. I’ve looked into directories and couldn’t find any mention of them in the C API. Is there a directory layer for C, and if not, is the implementation relatively simple?

2. Any guesses as to when Redwood will be ready?

Appreciate the help, thanks!

---

<div class="post-metadata">

**Author:** ![ananthakumaran](https://sea1.discourse-cdn.com/foundationdb/user_avatar/forums.foundationdb.org/ananthakumaran/32/526_2.png) [@ananthakumaran](https://forums.foundationdb.org/u/ananthakumaran)\
**Post date:** [March 17, 2019, 6:11am UTC](https://forums.foundationdb.org/t/how-does-foundationdb-store-keys-with-duplicate-prefixes/1234/4 "2019-03-17T06:11:23Z")

</div>

> [@jonahwest](#):
>
> - I’ve looked into directories and couldn’t find any mention of them in the C API. Is there a directory layer for C, and if not, is the implementation relatively simple?

directory implementation is not part of the C API. It is implemented as an independent layer on each language bindings. AFAIK, there is no formal spec for the directory layer, so one would have to port the current implementation. But there is a tool called [bindings tester](https://github.com/apple/foundationdb/blob/master/bindings/bindingtester/spec/directoryLayerTester.md) to verify the implementation, more information can be found at [Creating New Bindings](https://forums.foundationdb.org/t/creating-new-bindings/207) thread
