Databases: Which one's right for me?

Tim Peters at
Wed Jan 14 04:35:31 CET 2004

[Aaron Watters]
> Alright, just for yucks.
> Total blood supply must be kept above 50 except during emergencies.
> Two transactions notice that there are 40 in bin 1 and 40 in bin two,
> so one takes 30 units from bin 1 and the other takes 30 units from
> bin 2.

If you want to do this with ZODB, the first thing I'd recommend is that you
simply refrain from writing your app to perform concurrent transactions.
The "I" in ACID you're on about here works the way you want it to then.
BTW, unless you're also using ZEO, you can't open a ZODB database in more
than one process at a time, so it takes some work on your part for
concurrent transactions to be possible.

If this is the only blood supply in the country, thousands of hospitals hook
up to it over the net, and you need the performance true concurrency can
provide, then you've got more work to do.

Easiest would probably be to treat it like your checking-account example,
adding a member to the "blood supply" class recording total units of blood
on hand.  Then it's exactly like your checking-account example, and the same
strategies apply (meaning you'll get a ConflictError on all but the first to
commit of a batch of concurrent transactions trying to withdraw blood, and,
if it's not good enough for your performance needs to retry failing
transactions, you can go on to supply a conflict resolution method that
suppresses the ConflictError whenever the total remaining exceeds 50 units;
then the only transactions that fail would be those that truly require
dropping the total to <= 50 units).  I'll note here that ZODB holds Python
objects of arbitrary user-defined classes, so the idea of adding class
invariants is quite natural.

> Or even return to the original problem assuming that the balance
> doesn't change but the debits are entered as separate journal
> entries, where the current balance is computed on the fly as the old
> balance less withdrawals...

You can figure this out on your own, if you want to use ZODB to solve it.

> Sorry, I just don't know when to shut up, I know.  But when I see
> ACID I assume these things are not a problem.

No matter how often the world disappoints you <0.9 wink>?

> ps: Tim anticipated this reply in his post somewhat, but wasn't
>   concrete enough for my taste.

I'm not a DB expert -- I don't even talk the talk.  If you want to
accomplish something with ZODB, though, I can usually help (if only by
reminding you of the zodb-dev list, where you're conspicuous by absence

More information about the Python-list mailing list