Git Product home page Git Product logo

key-value-store's Introduction


Version-controlled Key Value Store API

This is an API that can be used to query a version-controlled key value store. I've delete it from the cloud so this API is currently unavailable. Please contact me if you want to use and test this API in production.

API endpoints

(Temporarily unavailable)Base path: http://key-value-store.ap-southeast-1.elasticbeanstalk.com/api/v1

Http Method Function Example Parameters Example Response
/get_all_records GET Returns JSON Array of all records data and their values currently stored in the DB N/A
{
    "data": [
        {
            "key": "key7",
            "value": "example text content of key 7.",
            "timestamp": 1656397200
        },
        {
            "key": "key7",
            "value": "\t example text content of key 7",
            "timestamp": 1656397211
        },
        {
            "key": "key10",
            "value": "example text content of key 10.",
            "timestamp": 1656483600
        }
    ]
}
/object/{key} GET Return the key's value at a specific time /object/key7
{
    "data": {
        "key": "key7",
        "value": "\t example text content of key 7",
        "timestamp": 1656397211
    }
}
/object/{key} GET Return the key's latest value /object/key7?timestamp=1656397200
{
    "data": {
        "key": "key7",
        "value": "\t new example text content of key 7",
        "timestamp": 1656397200
    }
}
/object POST Store key value pair request body: {"mykey" : "value1"}
{
    "data": {
        "key": "mykey",
        "value": "value1",
        "timestamp": 1719344835
    }
}

Architecture

the cloud infrastructure resource, DynamoDb are defined and provisioned using AWS Cloudformation. Deployment to Elastic Beanstalk environment has been made using awsebcli. This is the architecture used. Architecture diagram

Data model

The DynamoDB data model looks like this.

Partition Key Sort Key
KeyValueStore key timestamp

Example Data Model

Please note that data model design of the dynamodb table varies depending on the data size and predicted read&write frequency. For example, if the predicted read&frequency rate is not that high, we could create a Global Secondary Index(GSI) that has a constant static key like "ALL_ITEMS" as the partition key. By doing so, the query to get all records will become more efficient since dynamodb query perfomance will be very fast if we specify partition key during query. On the other hand, if the read&frequency rate is predicted to be very high, we shall consider partition key sharding.

Coverage report

#6 (comment)

Environment setup to run locally

Requirements

You need these on your computer before you can proceed with the setup.

  • PHP >= 8.2
  • aws cli
  • dynamodb local

To Run locally

  1. Clone this repository
$ git clone https://github.com/SarahTeoh/key-value-store.git 
$ cd key-value-store 
  1. Set up configuration
$ cp .env.example .env

Open .env file and configure the DYNAMODB_* and AWS_*.

  • DYNAMODB_CONNECTION: 'local' or 'test' for local
  • DYNAMODB_LOCAL_ENDPOINT: Your DynamoDB local endpoint with port
  • DYNAMODB_TABLE_NAME: DynamoDB table name you've created.
  • AWS_ACCESS_KEY_ID
  • AWS_SECRET_ACCESS_KEY
  • AWS_DEFAULT_REGION
  1. Install PHP dependencies
$ composer install
  1. Generate application key
$ php artisan key:generate
  1. Create dynamodb table in dynamodb local
aws dynamodb create-table --cli-input-json file://database/create-dynamodb-table.json --endpoint-url http://localhost:8000 

Change the endpoint url to your dynamodb local endpoint url.

  1. Check table created
aws dynamodb list-tables --endpoint-url http://localhost:8000
  1. Seed local dynamodb table
php artisan db:seed --class=KeyValueSeeder
  1. Run the dev server (the output will give the address):
$ php artisan serve

That's it! You can use curl or Postman to try the API.

key-value-store's People

Contributors

sarahteoh avatar

Watchers

 avatar  avatar

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.