Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here is the deal -</p> <ul> <li>Seller lists his sweatshirt</li> <li>Person #1 adds the sweatshirt to his cart</li> <li>Person #2 adds the same sweatshirt to his cart</li> <li>Person #1 checks out via PayPal</li> <li>Prevent both of them from end up buying same Item which has 1 quantity in your inventory.</li> </ul> <p>One way to handle this scenario in my opinion is(Which is a kind of upgraded version of your <strong>option #1</strong>)-</p> <p>When Person 1 adds an item in their cart you will(if not then you should) be changing the order status i.e. <strong>in cart</strong>, <strong>address</strong>, <strong>payment</strong>, <strong>complete</strong> etc. </p> <p>So when <strong>Person 1</strong> adds <strong>Item A</strong> in their cart(status: <code>in cart</code>) block it for 10 minutes for others(<strong>Person 2</strong>) to add them into their <strong><em>cart</em></strong>. Now you need to have a <strong>rake script</strong> or <strong>Delayed Job</strong> using <strong>crone job</strong> running on your <strong>server</strong> which checks for every <strong>products</strong>, in this case <code>Item A</code> in <strong><code>orders table</code></strong> with <strong><code>in cart</code></strong> status for 10 or more than 10 minutes and flush/ remove those <strong>products</strong> from that <strong>row</strong>. Which will enable others(<strong>Person 2</strong>) to add that Item into their cart. And have others(<strong>Person 2</strong>) and <strong>Person 1</strong> updated about your process of this 10 minutes flushing thing with some sort of notice. For example: <strong>Item 1 Will be available in <code>Time Counter running</code></strong> to <strong>Person 2</strong> and <strong>Item 1 will go in <code>Time Counter running</code></strong> to <strong>Person 1</strong>. Here this process will make a sense of urgency in users mind and you'll have a control over your inventory from not getting an item sold more than its <strong>count on hand</strong>/ <strong>quantity</strong>. You can check this website for a live and running implementation - <a href="http://www.thepeacockparade.com/" rel="noreferrer">http://www.thepeacockparade.com/</a></p> <p>Hope it gives you a fair idea to handle this situation. And yes if, you get any better way to do the same thing please, do keep me updated about it because, I'm also looking for an upgrade.</p> <p>Thanks</p> <p><strong>Update on performance</strong></p> <p>After implementing this process you may end up with some <strong>performance issues</strong> on your website. One way I figured out a way to keep your application running and, serving your customers and, the background process synced at the same time is, If you <strong>use</strong> <strong><code>amazon rds</code></strong> or any other <strong>cloud database service</strong> you can have two different application server altogether. One for your customers to serve and one for performing background processes such as, cleaning temporary data, files, rake tasks, uploading data etc. And since you have your application <strong>database</strong> totally outside of you application servers, it can be updated from both applications. So, it will keep your main application serving even better to its users instead of starving for memory used by background processes. </p> <p><strong>Update on database settings</strong></p> <p>Rails is awesome when it comes to <strong>database</strong>, <strong>tables</strong> and <strong>associations</strong>. If you are new to <strong>amazon cloud database service</strong> then, checkout their plans here: <a href="http://aws.amazon.com/rds/pricing" rel="noreferrer">http://aws.amazon.com/rds/pricing</a>. Best part about having your database on <strong>amazon rds</strong> are -</p> <ul> <li>You are free to select the near <strong>endpoint/ server location</strong> to serve your database for your application, which will reduce latency of your <strong>db queries</strong> and your <strong>server load</strong> in processing them.</li> <li>You can use multiple applications to access it. Apparently for different purposes, i.e. One for uploading data, second for running analytics etc. </li> <li>You have to pay only for what you use.</li> <li>If anything(sometimes for some reasons I prefer being a pessimist) goes wrong and server crashes for any weird reason. You are not screwed!! Your <strong>DATABASE</strong> is safe. Just set up a new application and voila!! You are back in no time.</li> <li>You have freedom to automate <strong>database backup</strong> without messing your head into <strong>BASH SCRIPTS</strong>.</li> <li>You can expand it as your Business grow.</li> </ul> <p>To set up an <strong>amazon rds database</strong> go to your amazon rds console: <a href="https://console.aws.amazon.com/rds/home" rel="noreferrer">https://console.aws.amazon.com/rds/home</a>. Select your preferred <strong>region</strong> from <strong>Navigation</strong> pane on left side of the page. Click on "<strong>Launch DB Instance</strong>" button, select you preferred <strong>Database</strong> and follow rest of the flow, i.e. selecting instance type etc.</p> <p>Now if you have your <strong>rds instance</strong> running, you are able to see an endpoint something like this: <strong><code>database-name.random-string.region-endpoint.rds.amazonaws.com</code></strong>. In your <strong>rails application</strong> edit and update your <strong>config/database.yml</strong> to this:</p> <pre><code>production: adapter: mysql2 host: database-name.random-string.region-endpoint.rds.amazonaws.com encoding: utf8 reconnect: false database: databse-name username: master-username password: password </code></pre> <p>Looked surprised?? Yes, that's it!! You are all set to you use your application with your new <strong>amazon rds DB instance</strong>. Now <code>rake db:create</code> to test connection and <code>rake db:migrate</code> to create your <strong>tables</strong>.</p> <p>Here I'd like to add one more thing. If you care to make your life better then, you should use <strong>amazon s3(simple storage service)</strong> too. It's damn cheap and reliable, Check it out here: <a href="http://aws.amazon.com/s3/" rel="noreferrer">http://aws.amazon.com/s3/</a> </p> <p>Enjoy!!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload