Live data from Hacker News

Show HN: InstantDB – A Modern Firebase

github.com

151–160 of 308 posts

Re: Show HN: InstantDB – A Modern Firebase

#151

Earlier quoted context omitted.

This is an aside but “trifecta but with four” actually has an awesome name: “Superfecta”!

I would probably avoid naming Firebase alternatives with a prefix like “Super” at this time.

I am dumb. Why? Was there some failed/controversial thing?

Re: Show HN: InstantDB – A Modern Firebase

#152

Earlier quoted context omitted.

Maybe a dumb question, but why do I have to wrap in `db.transact` and `tx.*`? Why can't I just have a proxy object that handles that stuff under the hood? Naively, it seems more verbose than necessary. Also, I like that in Rails, there are ways to mutate just in memory, and then ways to push the change to DB. I can just assign, and then changes are only pushed when I call `save()`. Or if I want to do it all-in-one, I…

This is a great question. We are working on a more concise transaction API, and are still in the design phase. Writing a `user.save()` could be a good idea, but it opens up a question about how to do transactions. For example, saving _both_ user and post together). I could see a variant where we return proxied objects from `useQuery`. What would your ideal API look like?

We have an internal lib for data management that’s philosophically similar to linear too. I opted for having required transactions for developer safety.

Imagine that you support the model discussed above where it’s possible to update the local store optimistically without syncing back to the db. Now you’re one missing .save() away from having everything look like it’s working in the frontend when really nothing is persisting. It’s the sort of foot gun that you might regret supporting.

Our model is slightly different in that we require the .save() on objects to create the mutation for the sync. The primary reason is that we’re syncing back to real tables in Postgres and require referential integrity etc to be maintained.

    tx((db) => {
      const author = new Author(db)
      author.save()
      article.name = “New name”
      article.author = author
      article.save()
    }
Mutating an object outside of a transaction is a hard error. Doing the mutation in a transaction but failing to call save within the same transaction is a hard error too.

Re: Show HN: InstantDB – A Modern Firebase

#153

Earlier quoted context omitted.

I would probably avoid naming Firebase alternatives with a prefix like “Super” at this time.

I am dumb. Why? Was there some failed/controversial thing?

Probably because of Supabase, I think.

Re: Show HN: InstantDB – A Modern Firebase

#155
I saw the reference to “apps like Figma” and as one of the people that worked on Framer’s (also a canvas based app) database which is also local+multiplayer I find it hard to imagine how to effectively synchronize canvas data with a relational database like Postgres effectively. Users will frequently work on thousands of nodes in parallel and perform dragging updates that occur at 60 FPS and should at least be propagated to other clients frequently.

Does Instant have a way to merge many frequent updates into fewer Postgres transactions while maintaining high frequency for multiplayer?

Regardless this is super cool for so many other things where you’re modifying more regular app data. Apps often have bugs when attempting to synchronize data across multiple endpoints and tend to drift over time when data mutation logic is spread across the code base. Just being able to treat the data as one big object usually helps even if it seems to go against some principles (like microservices but don’t get me started on why that fails more often than not due to the discipline it requires).

Re: Show HN: InstantDB – A Modern Firebase

#157
post #55

This looks great. We use our own version of something much more naive which allows for the various benefits you have (but yours does more). Ours is also based on Linear but we go all in on mobx like they do too. It’s a great model where we have optimistic updates and a natural object graph to work with in typescript. I’ll have a play with this to see if it could eventually be used as a replacement. Noticed in your do…

I didn’t clock the use of “triples” as the store on first read. That’s a non-starter for existing dbs and pretty much a dead end for anyone who eventually wants a db structure they can use outside of this model.

Re: Show HN: InstantDB – A Modern Firebase

#158

One bit of feedback: Its always appreciated when code examples on websites are complete. Your example isn't complete -- where's the `transact` import coming from, or `useQuery`? Little minor details that go far as your product scales out to a wider user base.

Thank you for the feedback, this makes sense! I updated the example to include the imports: ``` import { init, tx, id } from "@instantdb/react"; const db = init({ appId: process.env.NEXT_PUBLIC_APP_ID, }); function Chat() { // 1. Read const { isLoading, error, data } = db.useQuery({ messages: {}, }); // 2. Write const addMessage = (message) => { db.transact(tx.messages[id()].update(message)); }; // 3. Render! return…

Much better!
Post reply on HN