DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Data Engineering
  3. AI/ML
  4. When Race Conditions and Unbounded Result Sets Are Actually the Solution: the resolution

When Race Conditions and Unbounded Result Sets Are Actually the Solution: the resolution

Oren Eini user avatar by
Oren Eini
·
Apr. 24, 11 · News
Like (0)
Save
Tweet
Share
1.50K Views

Join the DZone community and get the full member experience.

Join For Free

we discussed the problem in detail in my last post. as a reminder:

the requirement

starting at a given time, charge as many accounts as fast as possible. charging each account is a separate action, we don’t have the ability to do batching.

image_thumb2

the first question to ask, however, isn’t how we can get the data out of the database as fast as possible. the first question to ask is actually:

what are the limiting factors.

in this case, we have to make a separate request for each account. that means that we have to access a remote service, and that means we have to figure out whatever we can actually parallelize the work in any way.

most production systems would limit the number of concurrent calls that a single customer can make (to prevent a customer with a lot of servers from crashing their own systems).

let us say that we have 100,000 accounts to charge. and let us further say that the total time for a charge operation is in the order of 1 sec. what it means is that whatever we want, we are actually going to be limited by the processing capabilities on the accounts, not our own code.

a silly way of doing this would be something like:

var subscriptions = session.query<subscription>().where(s=>s.nextcharge < datetime.now);
foreach(var sub in subscriptions)
{
   sub.chargeaccount(); // 1 sec
}

this would be silly for several reasons:

  • it would take over a day to complete.
  • it would load a lot of data to memory, probably only to be used in several hours .
  • it puts a lot of strain on our own database and network backbone.

a better alternative would be to try to parallelize this. assuming that we can perform 5 concurrent requests, we can drop the processing time to just below six hours.

note where the major savings are, not in how we are actually doing stuff with the code, but rather in how much concurrency we can agree on with the accounts provider. just to note, let us say that they allow us 25 concurrent requests per second, we are still much better doing chunks of the data all the way rather than trying to process it all at once.

what i would actually do in this scenario is just load the ids of the subscriptions that we need to update into a queue and let a bunch of workers (may be on separate machines) feed off the queue and try to handle as many account charges as they can possibly manage.


Data (computing) Requests Database Processing workplace Memory (storage engine) Production (computer science) Machine

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • What Was the Question Again, ChatGPT?
  • Microservices Discovery With Eureka
  • An Introduction to Data Mesh
  • API Design Patterns Review

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: