Skip to content

kounkou/cloud-hasher

Repository files navigation

cloud-hasher

license

1. Description

Certain applications encounter challenges in efficiently allocating entities, such as events, to designated stores or nodes. Consider the scenario where a request needs to be directed to a server from a pool of available servers. The crucial question arises: which server should be selected, and what are the underlying reasons behind the choice?

I have previously addressed these inquiries in a project that can be accessed at this link: https://github.com/kounkou/hasherprovider. Within this project, I offer an educational implementation of the Hasherprovider in a cloud environment.

The objective is to enhance understanding of the allocation process and its significance within such applications.

2. System Design

The following is the architectural overview of the application. Please note that this architecture is intended solely for educational purposes and does not encompass all the best practices typically employed when designing such a project.

Screenshot 2025-05-19 at 10 15 48 PM

3. Installation

To install the entire stack locally, you will need to have :

  • Docker
  • Localstack

4. Deploy

bash install.sh

5. Launch basic tests

At the root of the project there is a send-requests.sh script that sends the following basic requests for testing purposes :

bash send-requests.sh blfglg7v2p # replace with corresponding API Gateway endpoint ID
✅ Successful Request

This command sends a valid payload with all required fields:

curl -X POST \
     -H "Content-Type: application/json" "https://$1.execute-api.localhost.localstack.cloud:4566/prod" \
     -d '{"nodes":["node1","node2"],"hashKeys":["node1"],"hashingType":"CONSISTENT_HASHING", "replicas":3}' | jq

Response:

{
  "statusCode": 200,
  "body": "[\"node1\"]"
}
❌ Failure Scenarios
1. ❌ Missing nodes
curl -X POST \
     -H "Content-Type: application/json" "https://$1.execute-api.localhost.localstack.cloud:4566/prod" \
     -d '{"nodes":[],"hashKeys":["key1"],"hashingType":"CONSISTENT_HASHING", "replicas":3}' | jq

Expected Response:

{
  "statusCode": 400,
  "body": "node list is empty"
}
2. ❌ Missing hashKeys
curl -X POST \
     -H "Content-Type: application/json" "https://$1.execute-api.localhost.localstack.cloud:4566/prod" \
     -d '{"nodes":["node1"],"hashKeys":[],"hashingType":"CONSISTENT_HASHING", "replicas":3}' | jq

Expected Response:

{
  "statusCode": 400,
  "body": "hash keys list is empty"
}
3. ❌ Invalid hashingType
curl -X POST \
     -H "Content-Type: application/json" "https://$1.execute-api.localhost.localstack.cloud:4566/prod" \
     -d '{"nodes":["node1"],"hashKeys":["key1"],"hashingType":"UNKNOWN", "replicas":3}' | jq

Expected Response:

{
  "statusCode": 400,
  "body": "unknown hashing type"
}
4. ❌ Negative replicas
curl -X POST \
     -H "Content-Type: application/json" "https://$1.execute-api.localhost.localstack.cloud:4566/prod" \
     -d '{"nodes":["node1"],"hashKeys":["key1"],"hashingType":"CONSISTENT_HASHING", "replicas":-1}' | jq

Expected Response:

{
  "statusCode": 400,
  "body": "replicas number should be positive or 0"
}

6. Other Testing

To perform test for the stack please run the following command

$ npm test

Sample result

> cloud-hasher@0.1.0 test
> jest

 PASS  test/cloud-hasher.test.ts (9.265 s)
  CloudHasherStack
    ✓ SQS Queue Created (219 ms)
    ✓ Lambda Created (114 ms)
    ✓ APIGateway Created (112 ms)

Test Suites: 1 passed, 1 total
Tests:       3 passed, 3 total
Snapshots:   0 total
Time:        9.481 s
Ran all test suites.

About

This project is a AWS CDK implementation of the hasherprovider here : https://github.com/kounkou/hasherprovider

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published