

A URL shortener with an interesting storage backend
source link: https://ols.wtf/2021/05/17/url-shortener.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

A URL shortener with an interesting storage backend
May 17th, 2021 · Tech · golang programming dns
If you follow my blog, or happen to keep up to date with what I create, then you will know that I have been using YAML as a storage backend for my applications for a while now. It’s relatively low maintenance but it is limited in terms of distributed systems. Sharing data across distributed systems is an extremely tricky feat. You have to be sure that data is propagating appropriately and caching is sensible so that you aren’t overloading your data source, but likewise aren’t serving stale data.
What if I could tell you that there was a data store you could be using that was redundant and distributed by design, allowed granular caching per record in your dataset, and is incredibly simple to set up and maintain. Snake oil this is not, this is DNS.
Now, storing data in DNS is not a new fad, in fact I spoke about this back in 2018. More recently there have been countless memes on social media about using Amazon’s Route53 DNS service as a data store, so I felt it was time to upgrade my URL shortener from using YAML to DNS as its storage medium.
What’s your favorite database?
Mine is Route 53.
It has a 100% SLA, you can query it, and DNS is fundamentally a large key-value store.
Listen to @AWSMorningBrief here: https://t.co/6OlOVFakko— Corey Quinn (@QuinnyPig) November 13, 2019
The resulting Go code is 59 LOC, including comments and double checking the resulting URL to forward to isn’t relative, seeing as we can’t even trust url.ParseRequestURI
to only give us absolute paths any more (not bitter).
So how does this URL shortener work? Well like most it has a base URL and then a shortcode at the end which correspods to a URL to redirect to. We also have a base domain which may or may not be the same as the base URL, and the flow happens thusly:
- HTTP request to
https://[base URL]/[shortcode]
(e.g.https://ols.wtf/_orgy
) - DNS TXT record lookup against
[shortcode].[base domain]
(e.g.orgy.short.ols.wtf
) - Contents of the TXT record are used to perform a 302 redirect (e.g.
https://ols.wtf/2021/05/10/orgy-personal-tech-stack.html
)
You want to create a new redirect? Create a TXT record with the URL to redirect to on your dedicated URL shortening subdomain. With these being individual DNS records, you can chop and change the TTL on each of them as you wish, and now you can run as many instances of this as you want with their distributed yet authoritative record of your data. Fantastic!
Praise for dns-url-shortener
- “significantly less ridiculous than using YAML as a datastore” - hoistbypetard on irc
Do you have a comment to make on this post? Start a discussion in my public inbox by emailing ~ols/[email protected]. You can see the inbox here.
Recommend
-
505
Kutt.it is a free and open source URL shortener with custom domains and stats.
-
102
Breviare :scissors: :v: Breviare is a minimalist URL shortener made in Javascript (NodeJS / ExpressJS / MongoDB / Ajax).
-
387
URL shortening is nothing new, it was originally made popular due to the 140 character limit of Twitter and the 160 character limit of SMS messages. https://trimlink.site https://trimlink....
-
25
When is a URL shortener not a URL shortener? 2011-08-16 by qntm The URL http://qntm.org...
-
16
Hot: Firefly 1.3.0 URL Shortener released Posted: 2011-02-01 - Last updated: 2019-06-05 Tagged
-
14
Screencast: Firefly URL shortener in less than 2.5 minutes Posted: 2010-07-12 - Last updated: 2019-06-05 Tagged...
-
100
Setup your own Firefly URL shortener in 2.5 minutes Posted: 2010-06-06 - Last updated: 2019-06-05 Tagged
-
20
Announcing Firefly, a ruby URL shortener Posted: 2010-03-29 - Last updated: 2019-06-05 Tagged ...
-
19
Really? Another Sinatra URL Shortener in Ruby? Posted: 2010-03-28 - Last updated: 2019-06-05 Tagged
-
13
TrymAPI based URL shortener with pay-as-you-go pricingDeveloper Tools
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK