java - Ways to generate roughly sequential Ids (32 bits & 64 bits sizes) in a distributed application -


what ways generate unique "roughly" sequential ids (32 bits & 64 bits sizes) in distributed application ?

[side note: db not provide facility.] do not want use 128 bits uuids.

edit: response!
of suggest using mysql db flickr's ticket servers, doubt using multiple servers(in order eliminate single point of failure) may disturb sequential nature of generated ids since servers may lag behind others. while ok lag of few id sequences cannot afford huge disturbances in sequentiality.

building on @chris' idea of having table generate "next" identity. more reliable way of doing have 2 servers , round-robin load-balancer. server 1 distributes odd numbers, server 2 distributes numbers. if lose 1 server, odds or evens, show still goes on.

flickr uses similar id system

http://code.flickr.com/blog/2010/02/08/ticket-servers-distributed-unique-primary-keys-on-the-cheap/

then creatively use mysql's atomic replace syntax follows:

create table `tickets64` (   `id` bigint(20) unsigned not null auto_increment,   `stub` char(1) not null default '',   primary key  (`id`),   unique key `stub` (`stub`) ) engine=myisam  replace tickets64 (stub) values ('a'); select last_insert_id(); 

where stub value sufficient generate next identity in atomic fashion.

update op chronology , sequence requirements

with chronology driver choices change litte - atomic state in spof - chris' idea in sql example. bottleneck, , it's state must durable prevent duplicate ids being issued.

to achieve chronology @ scale high-availability in distributed system, causal sequence algorithms pretty way go - there few out there:

  • lamport timestamps
  • vector clocks
  • dependency sequences
  • hierarchical clocks

the calling pattern quite different spof strategy, require track , pass memento of sequence, timestamp or version - session information sequence generating. guarantee causal order given sequence or item in distributed system. in cases event pk compound of item identifier + causal sequence id.


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -