https://discord.cloudflare.com logo
Join Discord
Powered by
# durable-objects
  • s

    Subh

    08/24/2021, 9:03 AM
    One sec
  • s

    Subh

    08/24/2021, 9:08 AM
    So Lets say I have
    Copy code
    class Comments {
      
    }
    
    class Posts {
       constructor(...args) {
        super(...args)
        this.comments = []
      }
    }
    
    class Users {
      constructor(...args) {
        super(...args)
        this.posts = []
      }
    }
    Now on this if I want to do use cases like, 1. Search by post names 2. Search/filter by users 3. Search/filter posts by dates
  • s

    Subh

    08/24/2021, 9:33 AM
    Basically, the example I have added in https://github.com/subhendukundu/worker-auth-providers Looking a bit boring. So I was thinking to add a more realistic example πŸ˜„
  • a

    albert

    08/24/2021, 9:44 AM
    Hmm, I honestly wouldn't use Durable Objects for that - a database with PostgREST would most likely be the better option.
  • s

    Subh

    08/24/2021, 9:45 AM
    For sure! I was thinking in terms of capabilities.
  • a

    albert

    08/24/2021, 9:47 AM
    There's
    Array.find()
    and
    Array.filter()
    if you need to search through an array, but it is not an option for a million records.
  • s

    Subh

    08/24/2021, 9:48 AM
    in real life, what colud be a max number? If you have an idea, would love to know.
  • a

    albert

    08/24/2021, 9:50 AM
    However many records you can search through in 500 ms πŸ˜›
  • s

    Subh

    08/24/2021, 9:50 AM
    haha πŸ˜„
  • s

    Subh

    08/24/2021, 9:50 AM
    I was just putting a test case
  • s

    Subh

    08/24/2021, 9:50 AM
    to see how many I can filter
  • s

    Subh

    08/24/2021, 9:51 AM
    while you gave me that answer
  • s

    Subh

    08/24/2021, 9:52 AM
    But thank you so much πŸ™‚ it helped.
  • r

    raRaRa

    08/24/2021, 9:55 AM
    Yeah I'd store posts and users in a db, and then query for them. However, you could technically have one DO per user and post, where the db would hold the key/id to it.
  • r

    raRaRa

    08/24/2021, 9:55 AM
    But I'm unsure what benefit it would give over just storing it in a db, unless you're thinking about some real-time actions with websockets
  • s

    Subh

    08/24/2021, 9:58 AM
    Yes, real-time actions with websockets That is the use case.
  • s

    Subh

    08/24/2021, 9:59 AM
    Basically just trying to put together a fun example with DO and workers WS.
  • r

    raRaRa

    08/24/2021, 10:01 AM
    Yeah same story here! In my case I'm creating a protoype of online pictionary, creating DO for the lobby and for each room. Still working on the frontend part, but can't wait to see how DO will perform πŸ™‚
  • r

    raRaRa

    08/24/2021, 10:02 AM
    Previously I just hosted a monolith on my computer, and since then I've been waiting for the serverless way to create fun simple online games. I think... DO + WS is the answer!
  • s

    Subh

    08/24/2021, 10:03 AM
    Ya, This is great use case. I have quite a few usecases in mind. Just to play around basically
  • r

    raRaRa

    08/24/2021, 10:04 AM
    I think in your case, you could have DO per post, showing how many users are reading the post, some real-time interactions, etc! πŸ™‚
  • r

    raRaRa

    08/24/2021, 10:05 AM
    Having one large DO for all posts wouldn't really scale
  • r

    raRaRa

    08/24/2021, 10:08 AM
    I must say I'm a little surprised how little attention DO is getting, based on it's capability and power. Perhaps a few blogs and real-time demos would do the trick for it to get more attention. When I first heard about DO, I wasn't too sure how it worked or how I could utilize it for my use cases. I only read over the doom blog, and I believe it was too technical and the doom network code was just too much! πŸ™‚
  • s

    Subh

    08/24/2021, 10:22 AM
    Exactly! I am sure @User and team definitely working on that. πŸ™‚ But ya, it would be fun use case I am trying to put together if I am able to pull it off.
  • r

    raRaRa

    08/24/2021, 10:23 AM
    Yeah, can't wait to see more experiments with DO + WS πŸ™‚
  • s

    Subh

    08/24/2021, 10:23 AM
    100%
  • s

    Subh

    08/24/2021, 10:26 AM
    hmm! there are two ways to go about this. 1. One DO, for User which has all of his posts. 2. One DO for each Posts
  • s

    Subh

    08/24/2021, 10:26 AM
    Seems 2nd one is better approach.
  • r

    raRaRa

    08/24/2021, 10:27 AM
    The second option would scale better, since each DO has its limits (can't scale vertically)
  • r

    raRaRa

    08/24/2021, 10:31 AM
    The User DO could fetch the Post DO that the user is reading. But I'm not too sure if an user DO is really needed. In my case I will have a GameRoom DO, where each user connected to it will have basic metadata such as UserId, username, etc. If I need more information about the user I could juse fetch his information from KV (or any other DB)
1...163164165...567Latest