KV database studies and proofs of concept
My implementation: "JFA Link Shortener" Terms of Use
- A KV-like NoSQL database, like AWS DynamoDB or Cloudflare KV
- A serverless functions provider, like AWS Lambda or Cloudflare Workers
- A way to interact with the API, like cURL or a frontend UI of any kind
Cloudflare
- Cloudflare account with Workers enabled
- Wrangler CLI (
npm install -g wrangler
) - Two KV namespaces created in Cloudflare:
- One for URL storage
- One for rate limiting
- Clone and set up:
$ git clone https://github.com/jfalava/link-shortener.git
$ cd link-shortener/cloudflare
$ npm install -g pnpm
$ pnpm install
- Create KV namespaces in Cloudflare dashboard or via the
wrangler cli
:
$ pnpx wrangler kv:namespace create "URL_STORAGE"
$ pnpx wrangler kv:namespace create "RATE_LIMIT"
- Configure
wrangler.toml
:
name = "<your project name>"
main = "src/index.ts"
compatibility_date = "2025-01-29"
compatibility_flags = ["nodejs_compat"]
routes = [{ pattern = "<your-domain>", custom_domain = true }]
[observability]
enabled = true
[placement]
mode = "smart"
[[kv_namespaces]]
binding = "URL_STORAGE"
id = "<URL_STORAGE id>"
[[kv_namespaces]]
binding = "RATE_LIMIT"
id = "<RATE_LIMIT id>"
- Deploy to Cloudflare:
$ pnpm run deploy
After deployment, your worker will be available at your-worker.your-subdomain.workers.dev
- AWS Lambda version of the API endpoint
- IBM Cloud Functions version of the API endpoint
- Self-hosted version of the code and the infrastructure required
- IaaC deployments for AWS and IBM Cloud