code: public void updateCounter(StorageTransaction transaction, String counterId, long delta) throws IOException {
      CounterSnapshot snapshot = getCounterSnapshot(counterId);
  
      // If delta is negative, try to update shards with excess usage first
      if (delta < 0) {
        Optional<Integer> shardIndex = snapshot.pickShardWithExcessUsage(delta);
        if (shardIndex.isPresent()) {
          updateCounterShard(transaction, counterId, delta, shardIndex.get(),
              snapshot.shardCapacity(shardIndex.get()));
          return;
        }
      }
  
      int shardIndex = snapshot.pickShardWithSpareCapacity(delta);
      updateCounterShard(transaction, counterId, delta, shardIndex, snapshot.shardCapacity(shardIndex));
    }
docs: Must be called within a TransactionCallable. Augments the transaction with certain operations
  that strongly consistently increment resp. decrement the counter referred to by counterId, and
  cause the transaction to fail to commit if the counter's associated limit is exceeded. Also
  spurious failures are possible.
  
  <p>Delta should be +/-1 for graceful behavior, due to how sharding is currently implemented.
  Updates with a larger delta are prone to spuriously fail even when the counter is not near to
  exceeding its limit. Failures are certain when delta >= limit / NUM_SHARDS + 1.