Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8888355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:00:38+00:00 2026-06-14T22:00:38+00:00

The Background Our clients use a service for which they set daily budget. This

  • 0

The Background

Our clients use a service for which they set daily budget. This is a prepaid service and we allocate a particular amount from user’s budget every day.

Tables:

  • budgets – how much we are allowed to spend per day
  • money – clients real balance
  • money_allocated – amount deducted from money that can be spent today (based on budgets)

There is a cron job that runs every few minutes and checks:

  • if user has money_allocated for a given day
  • if money_allocated >= budgets (user may increase budget during the day)

In the first case we allocate full amount of daily budget, in the latter – the difference between budget and already allocated amount for that day (in this case we create additional record in money_allocated for the same day).

Allocation has two stages – in the first round we add a row with status “pending” (allocation requested) and another cron checks all “pending” allocations and moves money from money to money_allocated if user has enough money. This changes status to “completed”.

The Problem

We have a cluster of application servers (under NLB) and above cron job runs on each of them which means that money can accidentally be allocated multiple times (or not allocated at all if we implement wrong “already allocated” triggers).

Our options include:

  • Run cron job on one server only – no redundancy, client complaints and money lost on failure
  • Add a unique index on money_allocated that goes like (client_id, date, amount) – won’t allocate more money for a given day if client doubles the budget or increases it multiple times by the same amount during the day

There is an option to record each movement in budgets and link all allocations to either “first allocation of the day” or “change of budget (id xxx)” (add this to the unique index as well). This does not look sexy enough, however.

Any other options? Any advice would be highly appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T22:00:39+00:00Added an answer on June 14, 2026 at 10:00 pm

    Ok, so I ended up running this on one of the cluster’s instances. If you use Amazon AWS and are in a similar situation, below is one of the options..

    On each machine, at the beginning of your cron job’s code, do the following:

    • Call describe_load_balancers (AWS API), parse the response to get a list/array of all instances
    • Get http://169.254.169.254/latest/meta-data/instance-id – this returns instance ID of the machine that is sending request
    • If received instance ID is #1 in the list/array of all instances – proceed, if not – exit

    Also, be sure to automatically replace unhealthy instances under this load balancer in short time as describe_load_balancers returns a list of both healthy and unhealthy instances. You may end up with a job not being done for a while if instance #1 goes down.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Background Our email vendor supports rss feeds for dynamic content, which we use successfully
This is the background... one of our server is crashed and I can't start
I'm having problems with a long-lived background ruby process on our server, which isn't
Background: Our web app uses the jquery.constrain.js plugin to handle data entry in some
I want to change the background color of our apps main window when a
Background: We're building an application that allows our customers to supply data in a
Background: We have a TFS server setup where me manage our source code and
How can I rewrite our commit history to ensure certain keywords never appear? Background:
Background: I'm using the (fantastic) Vim plugin python-mode , which includes the pep8 linter.
I was wondering if somebody has some insight on this issue. A little background

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.