Giter Club home page Giter Club logo

global_id's Introduction

Solution to an interview project: (part of) a system that generates ids guaranteed to be globally unique.

The main implementation is in global_id.py. A simple UDP server wrapping it can be found in global_id_udp.py.

All the code should work on Python >=3.6.9 (both CPython and PyPy).

To install development dependencies, run the following (preferably inside a virtual environment):

make install-dev

To run the tests:

make test
make coverage  # same as test, but generates a coverage report in htmlcov/

To run the static type checker:

make typing

Performance

I managed to generate over 100K ids/second with a simple UDP server using PyPy on a t3a.nano instance; see performance.md for details.

Answers to the problem questions

  1. Please describe your solution to get_id and why it is correct i.e. guaranteed globally unique.

See global_id.py docstring (Id structure).

  1. Please explain how your solution achieves the desired performance i.e. 100,000 or more requests per second per node. How did you verify this?

See performance.md.

  1. Please enumerate possible failure cases and describe how your solution correctly handles each case.

See the global_id.py docstring (Assumptions).

How did you verify correctness? Some example cases:

  • How do you manage uniqueness after a node crashes and restarts?

See the global_id.py docstring (Assumptions).

  • How do you manage uniqueness after the entire system fails and restarts?

See the global_id.py docstring (Assumptions).

  • How do you handle software defects?

Automated tests:

  • Tests for the implementation with smaller id sizes, for which we check exhaustively all the ids that can be generated.
  • Tests that spot-check the real-size implementation.

Static type checking for the core of the implementation.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.