MCPcopy Index your code
hub / github.com/GeneralElectric/snowizard

github.com/GeneralElectric/snowizard @v1.8.1

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.8.1 ↗ · + Follow
201 symbols 471 edges 25 files 45 documented · 22%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Snowizard

Build Status Coverage Status

Snowizard is an HTTP-based service for generating unique ID numbers at high scale with some simple guarantees.

Motivation

Snowizard is a Java port of Twitter's Snowflake thrift service presented as an HTTP-based Dropwizard service. Snowizard supports returning ID numbers as:

At GE, we were more interested in the uncoordinated aspects of Snowflake than its throughput requirements, so HTTP was fine for our needs. We also exposed the core of Snowflake as an embeddable module so it can be directly integrated into our applications. We don't have the guarantees that the Snowflake-Zookeeper integration was providing, but that was also acceptable to us. In places where we really needed high throughput, we leveraged the snowizard-core embeddeable module directly.

Requirements

Uncoordinated

For high availability within and across data centers, machines generating ids should not have to coordinate with each other.

(Roughly) Time Ordered

We have a number of API resources that assume an ordering (they let you look things up "since this id").

However, as a result of a large number of asynchronous operations, we already don't guarantee in-order delivery.

We can guarantee, however, that the id numbers will be k-sorted (references: http://portal.acm.org/citation.cfm?id=70413.70419 and http://portal.acm.org/citation.cfm?id=110778.110783) within a reasonable bound (we're promising 1s, but shooting for 10's of ms).

Directly Sortable

The ids should be sortable without loading the full objects that they represent. This sorting should be the above ordering.

Compact

There are many otherwise reasonable solutions to this problem that require 128bit numbers. For various reasons, we need to keep our ids under 64bits.

Highly Available

The id generation scheme should be at least as available as our related services.

Solution

  • Dropwizard service written in Java
  • id is composed of:
  • time - 41 bits (millisecond precision w/ a custom epoch gives us 69 years)
  • configured machine id - 10 bits - gives us up to 1024 machines
  • sequence number - 12 bits - rolls over every 4096 per machine (with protection to avoid rollover in the same ms)

System Clock Dependency

You should use NTP to keep your system clock accurate. Snowizard protects from non-monotonic clocks, i.e. clocks that run backwards. If your clock is running fast and NTP tells it to repeat a few milliseconds, Snowizard will refuse to generate ids until a time that is after the last time we generated an id. Even better, run in a mode where ntp won't move the clock backwards. See http://wiki.dovecot.org/TimeMovedBackwards#Time_synchronization for tips on how to do this.

Contributing

To contribute:

  1. fork the project
  2. make a branch for each thing you want to do (don't put everything in your master branch: we don't want to cherry-pick and we may not want everything)
  3. send a pull request to jplock

Building

To build and test, run mvn test.

Extension points exported contracts — how you extend this code

SnowizardResponseOrBuilder (Interface)
(no doc) [3 implementers]
snowizard-api/src/main/java/com/ge/snowizard/api/protos/SnowizardProtos.java

Core symbols most depended-on inside this repo

getId
called by 27
snowizard-api/src/main/java/com/ge/snowizard/api/protos/SnowizardProtos.java
nextId
called by 16
snowizard-core/src/main/java/com/ge/snowizard/core/IdWorker.java
build
called by 13
snowizard-api/src/main/java/com/ge/snowizard/api/protos/SnowizardProtos.java
getStatus
called by 11
snowizard-application/src/main/java/com/ge/snowizard/application/exceptions/SnowizardException.java
newBuilder
called by 7
snowizard-api/src/main/java/com/ge/snowizard/api/protos/SnowizardProtos.java
getSequence
called by 4
snowizard-core/src/main/java/com/ge/snowizard/core/IdWorker.java
isValidUserAgent
called by 4
snowizard-core/src/main/java/com/ge/snowizard/core/IdWorker.java
getUnknownFields
called by 4
snowizard-api/src/main/java/com/ge/snowizard/api/protos/SnowizardProtos.java

Shape

Method 170
Class 30
Interface 1

Languages

Java100%

Modules by API surface

snowizard-api/src/main/java/com/ge/snowizard/api/protos/SnowizardProtos.java53 symbols
snowizard-core/src/test/java/com/ge/snowizard/core/IdWorkerTest.java32 symbols
snowizard-core/src/main/java/com/ge/snowizard/core/IdWorker.java13 symbols
snowizard-application/src/test/java/com/ge/snowizard/application/resources/IdResourceTest.java13 symbols
snowizard-client/src/main/java/com/ge/snowizard/client/SnowizardClient.java9 symbols
snowizard-application/src/main/java/com/ge/snowizard/application/config/SnowizardConfiguration.java7 symbols
snowizard-application/src/main/java/com/ge/snowizard/application/SnowizardApplication.java7 symbols
snowizard-api/src/main/java/com/ge/snowizard/api/SnowizardError.java7 symbols
snowizard-api/src/main/java/com/ge/snowizard/api/Id.java7 symbols
snowizard-application/src/test/java/com/ge/snowizard/application/SnowizardApplicationTest.java6 symbols
snowizard-application/src/main/java/com/ge/snowizard/application/resources/IdResource.java6 symbols
snowizard-api/src/test/java/com/ge/snowizard/api/SnowizardErrorTest.java6 symbols

For agents

$ claude mcp add snowizard \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact