# UUID or bigserial for primary key

**URL:** <https://forum.yugabyte.com/t/uuid-or-bigserial-for-primary-key/1433>\
**Category:** General\
**Created:** [February 7, 2022, 5:06pm UTC](https://forum.yugabyte.com/t/uuid-or-bigserial-for-primary-key/1433 "2022-02-07T17:06:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![selcukbey](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.yugabyte.com/selcukbey/32/415_2.png) [@selcukbey](https://forum.yugabyte.com/u/selcukbey)\
**Post date:** [February 7, 2022, 5:06pm UTC](https://forum.yugabyte.com/t/uuid-or-bigserial-for-primary-key/1433/1 "2022-02-07T17:06:42Z")

</div>

Hi!  
Should I use bigserial/bigint or UUID as Primary key at Yugabyte?  
We think it is much more reasonable to use bigserial because big serial is 8byte and UUID is 16byte.  
Are there any advantageous or disadvantageous of using bigserial or UUID?

Or are there any other unique types that hold 8 byte of space and like UUID(no-collision)?  
Thanks!

---

<div class="post-metadata">

**Author:** ![FranckPachot](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.yugabyte.com/franckpachot/32/353_2.png) [@FranckPachot](https://forum.yugabyte.com/u/FranckPachot)\
**Post date:** [February 7, 2022, 5:13pm UTC](https://forum.yugabyte.com/t/uuid-or-bigserial-for-primary-key/1433/2 "2022-02-07T17:13:38Z")

</div>

Hi, I’ve written about it:

> **[UUID or cached sequences?](https://dev.to/yugabyte/uuid-or-cached-sequences-42fi)**
>
> One reason why people choose a UUID for the surrogate key is scalability. Because it generates unique...

Bigserial is not so nice because you can’t set the sequence cache. `bigint generated always as identity` is good. I like UUID when exposed to the users so that it doesn’t disclose any info. But primary keys should not be exposed anyway.

---

<div class="post-metadata">

**Author:** ![dorian\_yugabyte](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.yugabyte.com/dorian_yugabyte/32/206_2.png) [@dorian\_yugabyte](https://forum.yugabyte.com/u/dorian_yugabyte)\
**Post date:** [February 7, 2022, 5:21pm UTC](https://forum.yugabyte.com/t/uuid-or-bigserial-for-primary-key/1433/3 "2022-02-07T17:21:46Z")

</div>

> [@selcukbey](#):
>
> Or are there any other unique types that hold 8 byte of space and like UUID(no-collision)?

There is twitter snowflake id. But you have to generate them in your client code.

---

<div class="post-metadata">

**Author:** ![selcukbey](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.yugabyte.com/selcukbey/32/415_2.png) [@selcukbey](https://forum.yugabyte.com/u/selcukbey)\
**Post date:** [February 8, 2022, 7:48am UTC](https://forum.yugabyte.com/t/uuid-or-bigserial-for-primary-key/1433/4 "2022-02-08T07:48:37Z")

</div>

@FranckPachot @dorian_yugabyte Thanks for your fast anwers!

> [@dorian\_yugabyte](#):
>
> There is twitter snowflake id. But you have to generate them in your client code.

It looks like I can use Snowflake. I have a column that holds a date named CreatedDate and it looks like I can use the timestamp at primary key (snowflake) instead of that column.  
I will storage Snowflake in bigint (8byte-64bit) type at Yugabyte, is it correct?

---

<div class="post-metadata">

**Author:** ![dorian\_yugabyte](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.yugabyte.com/dorian_yugabyte/32/206_2.png) [@dorian\_yugabyte](https://forum.yugabyte.com/u/dorian_yugabyte)\
**Post date:** [February 8, 2022, 7:53am UTC](https://forum.yugabyte.com/t/uuid-or-bigserial-for-primary-key/1433/5 "2022-02-08T07:53:17Z")

</div>

> [@selcukbey](#):
>
> I will storage Snowflake in bigint (8byte-64bit) type at Yugabyte, is it correct?

Assuming you are generating them correctly, yes.
