Coding an Auction House

Поделиться
HTML-код
  • Опубликовано: 5 окт 2024
  • voidpet.com/
    shop.voidpet.com/
    Linda's TikTok: / lindashad
    #benawad #voidpet #VoidLog
    ----
    Follow me online: voidpet.com/be...

Комментарии • 204

  • @mattickx
    @mattickx 2 года назад +79

    3:36 I would trigger "Adding 1 minute to the auction" only when < 1 minute (or some other low amount) is left on the auction. To avoid very long running auctions

  • @cvcvka588
    @cvcvka588 2 года назад +256

    The implementation is sick but I think that the auction house interface could look less like a corporate mobile app. Great content!

    • @NotesNNotes
      @NotesNNotes 2 года назад +15

      I just assume the UI will go through several iterations before it's polished and this can be done last

    • @cvcvka588
      @cvcvka588 2 года назад +1

      @@NotesNNotes Yeah I believe that the UI was just a quick prototype so they could implement and test the functionality first.

    • @b1zzler
      @b1zzler 2 года назад +1

      It looks a bit mobile but I'm not sure I would say it' looks "corporate".

  • @user-zq8bt6hv9k
    @user-zq8bt6hv9k 2 года назад +39

    It looks like a web/corporate app, doesn't feel like an auction house in a game

    • @berrywarmer11
      @berrywarmer11 2 года назад +3

      fair point, but the core functionality is a simpler version of the WoW AH many of us (like probably Ben) have used for years. The piece missing is the design aesthetic feeling more like you're in a game world, but Ben's a developer at heart and probably doesn't have an army of designers to manufacture game assets to make it look "gamey" . For example, the WoW AH has customized borders, currency, cursors and fonts that all provide a common design language that might make sense in a sort of medieval themed game. Ben's app looks like a pretty "corporate webapp" because it's very minimalist in comparison, which is pretty common in modern UI design language these days
      In other words: you guys are looking for this to look like it came from a professional game studio, which it didn't haha

  • @xzero01501
    @xzero01501 2 года назад +37

    It'd be typical to model bids (and most financial information) as transactional logs. Where the current price is calculated as max(bid) over (group by item). And then you cache the result of that query and invalidate it using a before insert trigger on the table.

  • @ImperiumLibertas
    @ImperiumLibertas 2 года назад +48

    >The auction takes a cut
    >Because this is the free market
    Lol

  • @jomarkpangan9362
    @jomarkpangan9362 2 года назад +110

    I really missed this type of content. Welcome back champ.

  • @michawezowski2573
    @michawezowski2573 2 года назад +93

    Since you're running postgres, you could avoid some ravioli in the action house by using locks with skip locked (inside transaction):
    a bit like this: "select * from "AuctionItem" where "endsAt" < now() for update skip locked limit 50"
    this code is safe to run concurrently (will not return the same row in two separate queries), so you can remove the sleeps and redis ravioli ;)

    • @themisir
      @themisir 2 года назад +1

      There still might be issue. Take this example:
      1. node1 queries database gets 50 items
      2. node1 finishes query and starts processing those items
      3. node2 sends db query just after node1 finishes the query and before starting processing
      4. node2 gets same result as node1 and starts processing same items
      So yeah, as you can see using db lock will solve one part of the solution but the whole lock needs to be applied to the whole processing part rather than query itself in order to solve race condition.

    • @michawezowski2573
      @michawezowski2573 2 года назад

      @@themisir In this situation you would definitely need to handle the data inside the transaction. Sorry if I wasn't clear on that ;) Cheers!

  • @MRAMAZRBALLZZ
    @MRAMAZRBALLZZ 2 года назад +9

    You should use a timeout that calls itself, intervals can get in a situation where if the job is slow and your job takes over a minute, it can start up the next job, slowing down your dB more etc

  • @fordneild2372
    @fordneild2372 2 года назад +8

    If the number of bids placed per minute exceeds 50, then there will be lag. Because of the way the distributed log is made, you can’t scale to multiple servers. Consider storing the key of the item(s) it’s handling. The pk of the row is a common distributed lock key. Thanks for making this Ben.

  • @fero5070
    @fero5070 2 года назад +10

    For the love of god, don't be lazy with the tables Ben. My company had a seminar where one of the consultants had a SQL crash course where he leared us everything we should NOT do. The biggest mistake he did in his 10+ years as a developer were being lazy when he made his databases. He said "being lazy with the databases saved me 1 day of work, but after a while the software has to scale and i ended up making what was 1 day of work to 1 week of work. The database sould always reflect the real world. Instead of setting up each home containing one sensor I ended up making sensors in homes as one table. Down the line, they wanted to keep track of when each sesonr was replaced which beacame a huge issue as we had none of that important data".

  • @JTWebMan
    @JTWebMan 2 года назад +7

    Also if you are using node you can capture the kill command (process.on) as well as hold on to the setInterval return value to call clearInterval if the kill command happens and the setInterval will stop.

  • @_vicary
    @_vicary 2 года назад +1

    Why does it look like every single app I see when I was interviewing bootcamp candidates?

  • @danibrosio
    @danibrosio 2 года назад +78

    It's so satisfying when things work in real time

  • @Finchley
    @Finchley 2 года назад +3

    Lower case SQL verbs…

  • @oogityboogity9979
    @oogityboogity9979 2 года назад +10

    When I see a new Ben Awad video, I watch the new Ben Awad video

  • @dkaraush
    @dkaraush 2 года назад +2

    so now he creates new project inside this so it doesn't look like he moved to new project

  • @bendotcodes
    @bendotcodes 2 года назад +42

    You would have make your life so much easier by using a scheduler. With AWS or GCP you can schedule cron job on a serverless function. That way you don't have to worry about having a main runner and concurrency. But hey, whatever works best depending on your context 😅.

    • @ithinktechnologies
      @ithinktechnologies 2 года назад +1

      Exactly..

    • @sonmangaking
      @sonmangaking 2 года назад

      U got it

    • @pharmokan
      @pharmokan 2 года назад +10

      Noooooo I don't want to leave my comfy cozy react workspace to handle this -- PROJECT CANCELED.

    • @alfredwindslow1894
      @alfredwindslow1894 2 года назад

      Can someone dumb this comment down for a noob pls

    • @user-zq8bt6hv9k
      @user-zq8bt6hv9k 2 года назад +2

      Serverless and cloud is for soy devs

  • @johndorian473
    @johndorian473 2 года назад +2

    Keep your health a priority too Ben. I just burnt out(anxiety and acid reflux) and had to take a week long leave just to relax and get my health back. I'm still weak but the setback helped put into perspective what's important. Everything in moderation and to disengage from work is key

  • @worldwide_wes
    @worldwide_wes 2 года назад +25

    0:25 that HR department really should start doing HR stuff

  • @mavdotj
    @mavdotj 2 года назад +4

    98% sure that microphone doesn't even work

  • @daoodqurashi4758
    @daoodqurashi4758 2 года назад +43

    serious ben why u doing this 😅😂

    • @NithinJune
      @NithinJune 2 года назад

      fr

    • @archonicmakes
      @archonicmakes 2 года назад +4

      ???????? because it's a project that makes him happy to work on????
      +billion dollar unicorn gaming company potential

    • @neociber24
      @neociber24 2 года назад

      Programing is fun

    • @mohammadanwar9848
      @mohammadanwar9848 2 года назад

      Doing what?

  • @mazwrld
    @mazwrld 2 года назад +1

    Working on an angular project right now and I'd rather die.. Send help

  • @300PIVOTMASTER
    @300PIVOTMASTER 2 года назад +1

    babe wakeup, new ben awad just droppped 🏃

  • @jannusdomingo5681
    @jannusdomingo5681 2 года назад +5

    Hey Ben, may I know what shaving blade/tool did you use? Btw, you always make the logic much easier and efficient! 🍻

  • @LawZist
    @LawZist 2 года назад +36

    Why not update the current bid in redis and asynchronous update the db with the redis current bid? If there are 100 concurrent bids it will cost 100 db updates

    • @LawZist
      @LawZist 2 года назад

      Actually if the bidding it is for days it may be good enough to just use postgres. WDY guys?

    • @xzero01501
      @xzero01501 2 года назад +14

      You should never ever ever update a cache directly. A cache should only be invalidated or populated. Trying to do anything "clever" like this will lead to development hell and horrific race conditions.
      The cost of updating an item in the dB will probably be tiny. If it starts to get expensive then you might want to use an in-memory database, which redis could also be used for, as can postgres.

    • @buzz1ebee
      @buzz1ebee 2 года назад +3

      @@xzero01501 i think they are suggesting using it more like a queue than a cache.

    • @LawZist
      @LawZist 2 года назад +2

      @@xzero01501 I mean to update the cache using a dedicate server and not directly from the client if that what you thinking..
      The cost may be tiny, but in a scenario where there are many users and the time is very critical for the biding, waiting to update the db can be very problematic just imagine 100 concurrent request to update the db will take all the connection pool and then what?

    • @xzero01501
      @xzero01501 2 года назад +1

      @@LawZist Even with blocking io and ~300 req/sec postgres would handle the updates just fine. It's general performant up to ~30ms response times.
      If you want faster than that then I'd rather have a fully in-memory database and drop postgres completely.
      As for redis as write-ahead queue with eventual consistency to disk: seems crazily over engineered

  • @pictureus
    @pictureus 2 года назад +1

    clear the interval as well so it's not continuously running in the background.

  • @nhanNguyen-wo8fy
    @nhanNguyen-wo8fy 2 года назад

    I've been waiting this for very long time.
    This will be another amazing journey.

  • @eloimartinez9446
    @eloimartinez9446 2 года назад +1

    Finally a programming video

  • @YoanArnaudov
    @YoanArnaudov 2 года назад +10

    You can use redis locks or any other lock to lock the update job and release when done. That way you’ll be 100% sure they don’t overlap.

  • @hectorg362
    @hectorg362 2 года назад +10

    Wtf, there just so much I need to learn to be a dev ;-;

    • @aaaa-hb5hw
      @aaaa-hb5hw 2 года назад +4

      start with small projects and you'll get there, no one was born an expert developer
      it takes time, hundres/thousands of debuguing hours and a lot of googling, but with time you'll be able to build that and more
      just be patient and enjoy you're time -unless you're debuguing ofc-

    • @alubhau
      @alubhau 2 года назад +1

      yes...everywhere you go there's infinite amount of known and unknown stuff to learn about...but to become a dev you have many guidelines online to learn enough to make awesome projects like voidpet

    • @UntrackedEndorphins
      @UntrackedEndorphins 2 года назад +2

      Well it's not like Ben learned all he knows in a weekend, y'know

    • @le0t0rr3z
      @le0t0rr3z 2 года назад

      Practice and you'll get there

  • @iamrooot
    @iamrooot 2 года назад +2

    what is that db modeling lang called? at 1:20

  • @OperationDarkside
    @OperationDarkside 2 года назад +2

    I'm new here, so sorry in advance, but if the game has a limit on the inventory, then could you use the auction house as an unlimited storage by putting your items in it for extremely high prices and a very long expiration date?

  • @zscoder
    @zscoder 2 года назад

    Was listening to this in the background. Thought you were discribing ebay 😂

  • @florimmaxhuni4718
    @florimmaxhuni4718 2 года назад +4

    I will try to use actor frameworks for concurrency .
    Good content by the way

  • @abprod1619
    @abprod1619 2 года назад +1

    Really enjoying this series, the high level overview with some code is nice to follow. Best of luck Ben. Remember us when this takes off and you make a portable VoidConsole.

  • @F.a797
    @F.a797 2 года назад +3

    Your intros never get old

  • @86thecake
    @86thecake 2 года назад

    five percent is everything

  • @bryanleblanc5648
    @bryanleblanc5648 2 года назад +16

    As a former Neopet connoisseur (aren't we all?), I can see how you're implementing the most important aspects of Neopets--selling stuff--with tons of improvements. No race conditions, maybe? No unlimited time, impossibly-high prices simply to show off your dope paintbrushes? Next you'll be telling me I don't need to play 3 crappy flashgames a day for my penance of 3,000 neopoints

  • @chizidotdev
    @chizidotdev 2 года назад +4

    Finally!! Some classic Ben Awad content🤌✨

  • @abhayvashokan5580
    @abhayvashokan5580 2 года назад +2

    Calling an hacky code a background job! Nice!

  • @abbasrangwala8088
    @abbasrangwala8088 2 года назад

    If this feature get popular, I don't think we will able to update every transaction.

  • @ahmedsaadsabit1749
    @ahmedsaadsabit1749 2 года назад +1

    i wish i could be as close to you as the mic

  • @beloaded3736
    @beloaded3736 2 года назад +1

    Ben thanks for sharing with us :D

  • @bojidaryovchev9995
    @bojidaryovchev9995 2 года назад

    the Prisma schema is just beautiful

  • @TwoTeaTee
    @TwoTeaTee 2 года назад

    Where's your corporate necktie?

  • @yasinnabi
    @yasinnabi 2 года назад +1

    “The pessimist sees difficulty in every opportunity. The optimist sees opportunity in every difficulty." - Winston Churchill $

  • @ranigiterman8011
    @ranigiterman8011 2 года назад

    Babe wake up Ben Awad uploaded a video

  • @spotted756
    @spotted756 2 года назад +16

    In order to check what server should run the background job, you can use environment variables, a prop file and so when you start the app in a docker container just pass the env variable as TRUE where you need that. I think redis is overengineering for that.

    • @themisir
      @themisir 2 года назад

      I don't think it's possible to dynamically change environment variables after the process starts.

    • @spotted756
      @spotted756 2 года назад

      @@themisir Nope, but you can set the env vars for each container from start, which should suffice.

    • @spotted756
      @spotted756 2 года назад

      You can achieve this with Kubernetes by using a replica with the env var set to true and another deployment with as many replicas as you want without that variable enabled.

  • @albster9389
    @albster9389 2 года назад

    This just sems like modern neopets

  • @ollydix
    @ollydix 2 года назад +2

    Regarding your background jobs. If you're hosting somewhere like CloudRun/Firebase whatever, just use a cron-job. The cron will hit 1 server via the ingress delegation. Set the cron to 1 minute that will run an interval there.

  • @flleaf
    @flleaf 2 года назад

    1:04 i was really hoping for him to say hypixel skyblock. it would be pretty funny

  • @j3gg
    @j3gg 2 года назад +1

    Yo Ben, how do you handle item returns if the user has filled up their inventory during the duration of the auction?

  • @ult1873
    @ult1873 2 года назад

    You have changed the shirt for the very first joke!

  • @RealKered
    @RealKered 2 года назад +2

    if your selling something starting the bit at 1000vm instead make the start the bid at 1vm then outbid yourself with 2 other accounts incrementing by 1vm until you hit 1000vm BOOM 1000 free extra minutes (16 hours) on the auction

    • @tomich20
      @tomich20 2 года назад

      Easy fix. Only add 1min if there is less than 1min remaining

    • @RealKered
      @RealKered 2 года назад

      @@tomich20 I was just making a joke but yea that would be a good idea

  • @bk1507
    @bk1507 2 года назад +1

    If you make the query on your background job idempotent, you won't have to worry about concurrency.

  • @grundle.chunder
    @grundle.chunder 2 года назад +3

    I think I'm 10 years older than you, but I want to be you when I grow up.

  • @MihaTech
    @MihaTech 2 года назад +4

    Is there going to be a "Going once, going twice..... sold, to the green elf with the white suit!" ???

  • @ingloriouspancake7529
    @ingloriouspancake7529 2 года назад

    These videos are good

  • @returnzero7492
    @returnzero7492 2 года назад +1

    Hey! You can use ".unref()" to kill running timer in Node.

  • @DODy-stare
    @DODy-stare 2 года назад

    What a very good video. I liked it very much. The variety of colors in this video makes it interesting. Thank you very much for the good work. I wish you happiness my frien👍👍👍👍👍👋👋👋👋👋👋

  • @yrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
    @yrrrrrrrrrrrrrrrrrrrrrrrrrrrrr 2 года назад

    broo this is great.... wow

  • @rhiannonmonks6894
    @rhiannonmonks6894 2 года назад

    Yay. Welcome back

  • @BearkFearGamer
    @BearkFearGamer 2 года назад

    Is hard to see a query with select * . So painfully

  • @bobkelso5681
    @bobkelso5681 2 года назад

    You should have used RxDB for state/replication etc

  • @pablosanchez5833
    @pablosanchez5833 2 года назад

    I thought exactly about the same solution before you describe it for the concurrent background jobs

  • @dev__adi
    @dev__adi 2 года назад +2

    was waiting for Swyx to plug Temporal but he left

  • @crustydev5561
    @crustydev5561 2 года назад

    Oh yeah, I'm subscribed to this guy...

  • @fedeabj
    @fedeabj 2 года назад +1

    What ORM is Ben using? 1:25

  • @avivshvitzky2459
    @avivshvitzky2459 2 года назад +19

    After suffering in startups for a few years, i've decided to jump into the water and create my own startup. I am the sole developer, and my partner is actually from China! This will be a project in China, which is very challenging, but I got courage.
    I'm not the greatest developer, hell sometimes I write shit code, but if you can make something work, that's what mattets, right?
    Cheers

    • @PierreMiniggio
      @PierreMiniggio 2 года назад +1

      Is your startup company registered in China, or in some other country ?

    • @avivshvitzky2459
      @avivshvitzky2459 2 года назад

      @@PierreMiniggio will be registered there by the partner

    • @PierreMiniggio
      @PierreMiniggio 2 года назад +1

      @@avivshvitzky2459 Be careful then, there are plenty of stories of foreigners joining adventures with a chinese national which then took advantage of the Chinese judicial system not being advantageous to foreigners to kick the foreigner out of the company when it grows.
      Legally speaking you're not on confortable grounds at all.

    • @lorenzogabriele9533
      @lorenzogabriele9533 2 года назад +1

      Great attitude! All today's gurus were once shitty developers so no need to worry about that :)

    • @PierreMiniggio
      @PierreMiniggio 2 года назад +9

      It would be better to register it in a country where the judicial system is more fair.
      I'd suggest talking your partner into that possibility (find another reason to justify it, maybe mention some other countries that allows you to pay less tax or no tax, idk).
      Your partner being a Chinese national, and you not being one, means he could, if he wants to, take over the company whenever he wants, either by his own will, or being pressured into it if you happen to build something that the Chinese government either doesn't like, or wants to take over.
      It happens on many level, there have been many small language schools in China opened by foreigners + chinese taken over by the chinese partners.
      You could look up how Uber got out of China because it was forced into selling for cheap to a Chinese company, etc.
      It's a real risk, that could happen to you.
      I strongly recommend you doing research on that stuff.
      You're puting yourself in a situation where you might invest time and money into something that will then disapear from your life completly without notice, nor your consent.

  • @felixc.programs8209
    @felixc.programs8209 2 года назад +1

    Really good content there! Your advices is one of the main reasons I swapped to the tech industry and started a RUclips channel myself. Thanks a lot!

  • @simontupy9706
    @simontupy9706 2 года назад +3

    poggers

  • @amineamine58
    @amineamine58 2 года назад

    good stuff

  • @romanext921
    @romanext921 2 года назад +2

    Hey Ben! For bidding race conditions you can write a test to make sure it works. Cheers!

  • @doggothedepressoexpresso
    @doggothedepressoexpresso 2 года назад

    i like how you are making a game witch isnt nft based as a lot of comapnys would have instantly made this one as there's a few that run simler to it also love your content

  • @PinguinoSod
    @PinguinoSod 2 года назад

    Why does HR department make business decisions?

  • @mikestaub
    @mikestaub 2 года назад

    nice work!

  • @darkwoodmovies
    @darkwoodmovies 2 года назад

    Excuse me copper ore in WoW costs 100 gold now!? Holy shit, I still remember when 1 gold was a lot.

  • @davidajaba
    @davidajaba 2 года назад

    Postgres locks rows, not tables... Locking tables are too expensive (not saying that it's not done)...

  • @keoagilempolokeng1310
    @keoagilempolokeng1310 2 года назад

    Where can I get that T-shirt?

  • @konichwaguys2850
    @konichwaguys2850 2 года назад +1

    Now i am trying to create a auction house hope for the best

    • @abdullahtahir1122
      @abdullahtahir1122 Год назад

      how can i do the concurrent background task for ending an auction using Node.js ?

  • @nostranostra1176
    @nostranostra1176 2 года назад

    Are you using prisma for the ORM ?

  • @Chrizz604
    @Chrizz604 2 года назад +1

    nice

  • @Vulcan58
    @Vulcan58 2 года назад

    Howdy! What language is this? I'm new to programming and want to develop games in the future, thanks.

  • @luizkc9540
    @luizkc9540 2 года назад

    Isn't TemTem a Pokemon MMORPG?

  • @lunaeclipse5768
    @lunaeclipse5768 2 года назад

    this is a lowkey discord endorsement
    i preferreed sign up with a "GMAIL"

  • @AJ-jo2ub
    @AJ-jo2ub 2 года назад

    Hey bro, you should get jacked for the 1milly on tiktok and surprise everyone with the lights off trend. If you need help getting in shape hmu.

  • @davidnogueira4140
    @davidnogueira4140 2 года назад

    So basically….eBay?

  • @vdemcak
    @vdemcak 2 года назад

    What ORM are you using?

    • @bodymassage9
      @bodymassage9 2 года назад

      judging from previous videos, typeorm

  • @suryavegeta12
    @suryavegeta12 2 года назад

    If the end goal is to become a Pokemon MMO like game and if there's already a Pokemon MMO like game i.e Pokemon MMO, Why would someone play this game?

  • @emile6264
    @emile6264 2 года назад

    If you don't set your transaction isolation at the serializable level you can get race conditions since the default is read commited (it will only see commits before the transaction started so concurrent updates won't see each other). You could also use a row lock with a Select For Update or you could use an advisory lock. In any case, I would keep the logic in the DB to avoid (create a pgsql function worst case) to avoid the round trip to the application.

  • @ekweisking2023
    @ekweisking2023 2 года назад

    I missed you bro

  • @basicduck
    @basicduck 2 года назад

    If you want help with server-side stuff I’m working with Go.

  • @user-cd6vy2jg6f
    @user-cd6vy2jg6f 2 года назад +1

    For item expiration you could have used
    dynamoDB ttl and set up dynamoDB streams.
    A stream record is emitted on the stream when items are deleted which you can have trigger lambda. The lambda can handle the transaction of who gets the item / who gets the money / etc.
    For the redis cache which facilitates a single server doing the background job - look up the leader election algorithm

    • @bjlapp
      @bjlapp 2 года назад

      The dynamoDB TTL function doesn’t quite work with this. It tells dynamo that a record may be deleted but doesn’t force the delete at the TTL time. In my experience with a small table 15-30 minutes beyond the TTL time is normal but the dynamo docs say it may take up to 48 hours. I think he’s looking for more up to date actions here.

    • @user-cd6vy2jg6f
      @user-cd6vy2jg6f 2 года назад

      @@bjlapp very good point. Forgot the TTL feature is variable

    • @georgemunyoro
      @georgemunyoro 2 года назад

      DynamoDB's TTL is variable but MongoDB's TTL would be a better simpler alternative. It deletes items within a minute, its API is also a lot more node friendly. Would have solved the whole problem without needing redis or keeping track of the running job

    • @user-cd6vy2jg6f
      @user-cd6vy2jg6f 2 года назад

      @@georgemunyoro does Mongos TTL give you an event stream though? An action needs to be performed on every delete. That’s why Dynamo was a good candidate because of DDB stream records

  • @peter_verduin
    @peter_verduin 2 года назад +1

    This seems really well thought out, the devs of Hypixel Skyblock could definitely learn a thing or two from you

  • @isheanesunigelmisi8400
    @isheanesunigelmisi8400 2 года назад +2

    The prodigal son has returned from Tik Tok

  • @peter8261
    @peter8261 2 года назад

    So in theory, could people collude to indefinitely extend the time of an auction by bidding and adding 1 minute to the timer? If they had enough money to do so?

    • @jaiv
      @jaiv 2 года назад

      yes but they gain nothing from that, and most attempts will end quickly because of the amount of money needed to keep going. once it ends, the last bidder would spend their money on it and waste a lot if they inflated the price. even if the bidder knew the seller, the auction house would take a cut which makes this idea less worth it. maybe someone would overpay to a friend to give them more money (until a trading system exists) but i see 0 reasons why multiple people would want to go back and forth, extending the timer

  • @James-25
    @James-25 2 года назад

    what is your origines ??

  • @jakecullimore1172
    @jakecullimore1172 2 года назад

    comment for the algorithm

  • @fb1000000
    @fb1000000 2 года назад

    Am I the only one with a crush on Ben? 🤠🙈

  • @ethio-code6509
    @ethio-code6509 2 года назад

    How many of you guys are looking to use this app?