Skip to content

SarahTeoh/key-value-store

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

63 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


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.

About

A version-controlled key-value store API

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published