I have a high-traffic site that records web hits in a table, Hits. There's logic in place so that duplicate hits are discarded (where the definition of what defines a hit as duplicate is arbitrary for the purposes of this example).
Problem: with multiple web servers running (against the same DB), two or more hits can arrive at the same time on different web servers and, from each server's perspective, none of them are duplicates (whereas were they serialized through a single server all but the first should be discarded). Hence, all of them get written to the Hits table.
Without altering the DB schema to force uniqueness on a field in the Hits table, how do I force Rails to synchronize the transaction to the database to guarantee that no duplicates are written? According to the documentation, ActiveRecord transactions are only enforced on a per-connection basis, which isn't good enough (as far as I can tell).