Help in prototyping a penny auction app

Those who are not sure of what a penny auction system is, you’re encouraged to visit or . I’m trying to build the prototype of the core part (bidding on a product) of this app. My development strategy is create a product with its

I should be able to start an auction from server by meteor-synced-cron package.

Lets assume the bid duration will be for 30 seconds so, expire_time will be start_time+30 sec when I create a product.

The approach i’ve been considering is to update the expire_time with current_server_time+30 sec field of the MongoDB whenever an user clicks/bid.

And I feel there are two ways to display the countdown timer in the client.

  1. Observing the difference of current_server_time and expire_time . which leads to knocking the database every second. which is kind of inefficient.
  2. running a countdown timer offline and only update the database whenever an user bid. and observing only the expire_time. If it changes , the countdown timer reset with 30 second.

I’m currently trying achieve the second one. I’ve modified an existing countdown timer collected from internet. let’s assume the method is
this method can run a countdown timer logging into the console. The problem is variables of this methods are not reactive. I can solve this by putting the second value in the session and using a helper.

But I find some difficulties here and looking for ideas from you.

  • when a user visit the site , he should be able to see the timer also. how do I handle that? If I try to count the number of products are in auction right now in the Meteor.isClient by a query , it’s returning me 0 as for the first time the miniMongo remains empty.

Any better solutions/ideas/suggestions are mostly welcome.

AS this post is quite large, you might get confused/lost. you are requested to knock me for any clarification.

Basically you’re right on track here. Option 2 is definitely the way to go. Update the DB only when you have to, i.e. when a user bids.

Of course, if you integrate some non-reactive JS then you will have to take care of the reactivity more manually – integration points between Meteor and non-reactive JS always require a bit of work. So yes, basically use something like Tracker.autorun or the Template-version of that method in order to reactively re-init your countdown JS so that it always reflects the current expire time whenever a new bid comes in.

I’m assuming you already have your publications and subscriptions set up correctly. Then this would indicate that your “init the countdown” script does not yet run reactively, i.e. within an autorun, so you may want to fix that as described above.

Again, you’re definitely on track, making workable decisions. Bridging non-Meteor with Meteor code can be a hard nut to crack initially, something to wrap your mind around, but once done is a very valuable tool in your Meteor development kit.

1 Like

Thanks for your suggestion.
I am still a new to this platform, Hopefully will get much more advice from you and this community as well.

@faysal @ seekr , i am working an app which behave like yours. Mine, basically show a list of items for bidding but should expire within the day.

My initial plan is that during publication, i will filter them already by using moment within the day function. My understanding is that since publication is reactive it has an internal timer to check if there are changes on the db and then update its publication.

Is my understanding correct?

@faysal maybe this will help you as well

I actually built one of these for my senior thesis when I graduated college. Good luck! :stuck_out_tongue:

It’s a bit of a pain in the ass to keep clients in sync with the timer. In my case it was a 10 second countdown, with the timer resetting on every bid. Timer reached 0 and the last person who bid won the item.

The way I implemented was that on second 0, the client sent a ‘ping’ to the server: “*Is this auction really at a time to close?” and if so, I closed the auction and sent off a ‘close’ beacon to all users.

If other users asked the same ‘question’ from their client, I just sent the same ‘close’ beacon.

Gist of it: Don’t modify the database every second. Just fire off 1 ‘request to close’ on second 0. Then have your server broadcast the closed message.

That’s the rundown of the hard part. I used SignalR and ASP.Net MVC3 back then, I imagine Meteor will make this much easier though! This app is like a match made in heaven for Meteor’s strengths.

@sergiotapia technically, the database isn’t being modified every second, it modifies it’s data only when it gets new click from any client and when the current time doesn’t pass the expire time

Even then I wouldn’t modify the database, imagine 20 people ‘playing’ an auction. Each click will overwrite something, why bother with that heartache. :stuck_out_tongue:

I would just listen to that “Hey it’s time to close!” request and if true return to all “Yep it’s closed.”

@ralpheiligan if you’re doing a similar apps like mine, why don’t we chat sometime to have some discussions about the production quality code so that both of us get a chance learn, though i know only a little of meteor

@sergiotapia but wouldn’t that be a confusion for user who clicks the ‘bid’ button immediately after the clock reset ? because he/she has to wait lets say 59 second in a one min duration auction play. Am i correct?

Hi have prototyped penny auction site ?. i am looking for it .