{
"$type": "site.standard.document",
"bskyPostRef": {
"cid": "bafyreihqlamdrcepgjim3ol5ttolagvqidcaer76xyeno4w7wfetg3txue",
"uri": "at://did:plc:xxrzfynfiasdpbxteqxi4jgq/app.bsky.feed.post/3mgfl7bqyc2g2"
},
"coverImage": {
"$type": "blob",
"ref": {
"$link": "bafkreicaoqmz7euh2zf6e4krbmt3aou6d4cin5py7ruu43bpvvsn3xhjeu"
},
"mimeType": "image/jpeg",
"size": 462417
},
"description": "The Tophhie Cloud Redirect Service will become a micro-service in its own right, and removed from the Tophhie Cloud API.",
"path": "/were-decoupling-the-tophhie-cloud-redirect-service/",
"publishedAt": "2026-03-06T14:58:46.000Z",
"site": "https://blog.tophhie.cloud",
"tags": [
"here"
],
"textContent": "The Tophhie Cloud API continues to grow, adding more and more endpoints. However, with that, comes an increase in the need for system resources, and additional complexity when it comes to troubleshooting one big API system.\n\nThat's why, today, we're decoupling the Tophhie Cloud Redirect Service into its own microservice.\n\nThose that know me by now, know, I love Cloudflare. If I can host a service on Cloudflare, I will. And the Redirect Service is no exception.\n\n## What's changed?\n\nFunctionally, nothing.\n\nThe service works in the exact same way it always has...\n\n * User goes to aka.tophhie.cloud/{shortname}\n * User is then redirected to the longer URL for that specific shortname\n * User can also go to aka.tophhie.cloud/index to get a full list of all redirect URLs\n\n\n\nThere... nothing has changed.\n\nArchitecturally, things have changed. Let's get into that.\n\n## The new Redirect Service Architecture\n\nSo, what actually powers the Redirect Service.\n\n * A Cloudflare Worker\n * A Cloudflare Hyperdrive connection to a MySQL database hosted in Azure\n * and a Cloudflare D1 Database for logging redirect requests\n\n\n\n### The Cloudflare Worker\n\nThe worker performs all the network requests! When you make a request to aka.tophhie.cloud you'll end up hitting this worker, and the worker processes the request.\n\nā¹ļø\n\nWant to check out the code for this worker...? It's here!\n\nThe code is quite simple for a service like this...\n\n 1. Request comes in.\n 2. We then do a check on the number of URL segments.\n 1. This is the number of / instances there are.\n 1. aka.tophhie.cloud/index == 1\n 2. aka.tophhie.cloud/this/is/not/right == 4\n 3. We make sure there's only one segment, and return an error if there is more than one.\n 4. The worker than initialises a connection to the MySQL database via Hyperdrive.\n 5. We then do a switch statement...\n 1. If the shortname is equal to \"index\", we perform an index request.\n 1. The index request fetches all redirect entries within the database that are currently \"published\", builds a JSON response, and returns that JSON.\n 2. If the shortname does not equal \"index\", we perform a redirect request.\n 1. The redirect request does a search in the database for that specific shortname, if one is found, the worker returns a Response.redirect object with the full URL from the database, and a 302 status code.\n 6. In each statement, we also log the request details to the Cloudflare D1 database for tracking and monitoring, so we can check for malicious activity, or particularly popular links.\n\n\n\n### The Cloudflare Hyperdrive Connection\n\nPreviously, the Tophhie Cloud API handled all SQL connections to the MySQL server. With the introduction of Cloudflare, this is now handed off to Cloudflare's Hyperdrive.\n\nA Zero Trust tunnel connection is configured to my Azure environment, allowing Cloudflare to securely connect to my MySQL database. Built in caching makes queries a lot quicker, and responses even faster.\n\nFor more information on Hyperdrive, look no further than the Cloudflare Docs here!\n\n### The Cloudflare D1 Database\n\nPreviously, logs were stored in Azure Table Storage. Whilst this worked, navigating the interface and querying the data was a bit cumbersome and often slow.\n\nThis data is now being stored in a Cloudflare D1 database. The interface allows for speedy, in-browser querying, and better readability.\n\nFor more information on D1, look no further than the Cloudflare Docs here!\n\n* * *\n\nRequests to the old Tophhie Cloud API Redirect endpoint will continue to function as usual for the short-term, until the endpoint is completely removed within the next month or so.\n\nAll requests to aka.tophhie.cloud will now be routed to the new Cloudflare Worker.\n\nUntil next time šš»",
"title": "We're decoupling the Tophhie Cloud Redirect Service āļøāš„",
"updatedAt": "2026-03-06T14:58:46.382Z"
}