Hacker Newsnew | past | comments | ask | show | jobs | submit | dimitrisnl's commentslogin

Noob question, but why no use ints for PK, and UUIDs for a public_id field?

If you put an index on the UUID field (because you have an API where you can retrieve objects with UUID) you have kind of the same problem, at least in Postgres where a primary key index or a secondary index are more or less the same (to the point is perfectly valid in pgsql to not have any primary key defined for the table, because storage on disk is done trough an internal ID and the indexes, being primary or not, just reference to the rowId in memory). Plus the waste of space of having 2 indexes for the same table.

Of course this is not always the case that is bad, for example if you have a lot of relations you can have only one table where you have the UUID field (and thus expensive index), and then the relations could use the more efficient int key for relations (for example you have an user entity with both int and uuid keys, and user attribute references the user with the int key, of course at the expense of a join if you need to retrieve one user attribute when retrieving the user is not needed).


You can create hash indexes in Postgres, so the secondary index uuid seems workable:

https://www.postgresql.org/docs/current/hash-index.html


*edit: sorry, misread that. My answer is not valid to your question.

original answer: because if you dont come up with these ints randomly they are sequential which can cause many unwanted situations where people can guess valid IDs and deduce things from that data. See https://en.wikipedia.org/wiki/German_tank_problem


Hence the presumed implication behind the public_id field in GP's comment: anywhere identifiers are exposed, you use the public_id field, thereby preventing ID guessing while still retaining the benefits of ordered IDs where internal lookups are concerned.

Edit: just saw your edit, sounds like we're on the same page!


So We make things hard in the backend because of leaky abstractions? Doesn't make sense imo.

Decades of security vulnerabilities and compromises because of sequential/guessable PKs is (only!) part of the reason we're here. Miss an authorization check anywhere in the application and you're spoon-feeding entire tables to anyone with the inclination to ask for it.

I also think we can use a combination of a PID - persistent ID (I always thought it was public) and an auto-increment integer ID. Having a unique key helps when migrating data between systems or referencing a piece of data in a different system. Also, using serial IDs in URLs and APIs can reveal sensitive information, e.g. how many items there are in the database.

One of the benefits of UUIDs is that you can easily merge data coming from multiple databases. Auto-increments cause collisions.

The article mentions microservices, which can increase the likelihood of collisions in sequential incremental keys.

One more reason to stay away from microservices, if possible.


Always try to avoid having two services using the same DB. Only way I'd ever consider sharing a DB is if only one service will ever modify it and all others only read.

Good luck enforcing that :)

The 'collision' is two service classes both trying to use one db.

If you separate them (i.e. microservices) the they no longer try to use one db.


There is nothing stopping multiple microservices from using the same DB, so of course this will happen in practice.

Sometimes it might even be for a good reason.


They haven't implemented RSC yet.


The post is mostly about Phoenix LiveView, while the title makes it about the framework.

To be honest one of the reasons I don't like Phoenix is that even if I opt-out of LV in the generators, I still get a lot of LV code.


Yup - an important distinction that wasn't obvious to me when I first jumped in. LiveViews are very opinionated and generate a ton of boilerplate. Not always a bad thing, but Elixir is elegant because of how spartan and expressive the code is - LiveView is kind of the opposite IMO.


what a timing


I have only good things to say about TanStack start. I know there's some fatigue when it comes to full-stack JS/TS frameworks, since they re-invent ways to do data fetching, but are not in any way batteries-included.

I prefer it over Next.js and the whole RSC story, and it has sensible features that I missed in Remix (server functions from everywhere [1], middleware, type safety)

I wouldn't pick it as a full-stack framework, I will always keep my backend separate, but for a SSR-capable TypeScript framework it's amazing.

[1]: https://tanstack.com/start/latest/docs/framework/react/serve...


Any good book recommendations?


Robin Williams - any of her books with "For non-Designers" in the title, even if it is old, it is gold


Chess, I play on Lichess[1]. I started about a year and a half ago.

[1]: https://lichess.org/


Try having a healthy relationship, kids, responsibilities, work, and some form of hobbies. If I don't write my thoughts, ideas, whatever, I lose the ball.


So, a bit like separating the grain from the chaff or, organizing all these different life experiences into an understandable and meaningful whole?


Oof. I'm sure Vercel might patch this issue. But I had had enough of these little annoyances. For example, the documented way to identify prefetches in the middleware has been broken for weeks (months?).

A lot of small issues that keep adding up. I'm not going to shill something else here, but I have a bit of Next.js fatigue lately. Still love the JS ecosystem though.

Anyway, thanks for bringing this up!


I moved away from Next.js, and switched to Astro. Originally I just wanted to go back to basics, but didn't want to bother with having to set up all my routes, templating, serving static assets, build tasks. Astro just handles all that, and it's SSR by default.

I also feel that Astro uses React/Vue as it was intended, as an interactive layer on top of HTML. It also made me realize how little I needed JS frameworks to begin with.

Next just started to feel like to much magic, the server actions felt weird, and just lots of things that required the "NextJS way".


I tried various astro sites, and as a user, a few things keep bugging me. - Visit their docs https://docs.astro.build/en/basics/astro-pages/ - Click `Routes` in the navigation

Now: 1. There's a flicker in the content where the sidebar moves on the left 2. The title displays `docs.astro.build` for a split second before it says "Routing | Docs"

Especially the second is quite annoying. I see it in every Astro site.


That seems to be mostly because of the way they've implemented their docs. It's definitely not something I have with my own sites.

The flicker seems to be because the collapsible nav items are done on the client, and closed by default.

I'm not sure where the title issues are coming from.


Here is one Astro site https://mayo.clumsy.fish/ with no flickers. Astro is pretty good but after trying RSCs I'm not going back.


I'm still using Next.js in my work and projects because I still think it may be the best way to ship React to production, but it used to be something fun, enjoyable and productive. sometimes I feel a bit sad about the direction it's going in since the move from pages to the app router.


The best way to ship React to production is with Vite. It opens up tons of options (Tanstack, RR, Simple SPA, whatever) and you don't even bring the hosting provider into the discussion.


This - I spent quite some time fighting the new Next.js conventions not working for me making a legit web app instead of traditional site, switched to vite and was like yay, things work again and so fast. Normally I am all about embracing the framework, but kept thinking for what was happening I could use PHP instead and host anywhere.


Curious, anything specific that you'd highlight compared to a setup like Remix that make it easier to ship with Next?


RSC


Well, they have consistent naming for a start.


Another follow-up. Some libraries[1] started to break from 15.1.8 onwards, so you had to downgrade to the vulnerable versions the author mentioned as well.

[1]: https://github.com/hashicorp/next-mdx-remote/issues/488


I share the sentiment. I think we will only be using Next.js for static sites/prebuilt SPA in the future.


Actually Next.js with App router (and with Pages being pushed out) is really bad for SPAs. See this thread: https://github.com/vercel/next.js/discussions/64660


> I think we will only be using Next.js for static sites/prebuilt SPA in the future.

With whats mentioned in the blog post I would not use it even from static builds.


You probably have better alternatives for that: Astro, React Router 7, TanStack.


A state-owned club, with half a billion spent on transfers in the last 5 years, is the correct office job inspiration. Congrats.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: