I am putting together a system design for something similar to Tiny URL. It provides an API for mapping a URL to a short URL. Once created the short URL can be used to access the original URL. This system seems to need to be both available and consistent at the same time (which I know is not possible).

Available - If the system is not available, requests to a short URL will start failing - which defeats the purpose of having a short URL.

Consistent - If a system is not consistent - a newly created tiny URL may not be accessible for a while. Also if you update an existing URL to point elsewhere, the changes might take a while to propagate.

How then can we decide to choose one over the other? What factors should we consider?

有帮助吗?

解决方案

It's a tradeoff that you evaluate against your use cases.

In this particular case you might choose as follows: Considering consistency, for the distribution technology/schemes you're considering how long is the typical or alternatively the expected max latency before the url is consistently available at all replicas. Is that too long for you? If not, forget about it.

In the "tiny url server" case you're "write once": Once the tiny url is created it is never changed. (Or very rarely.) Perhaps that latency to get initial consistency isn't a hurdle ... and if that's the case you can prioritize availability.

其他提示

The question boils down to: If there's a network partition (or just latency), would you rather serve old data, or not serve any data at all?

I think for a tiny URL service, it's pretty clear that possibly serving old data is better than not serving any data at all.

There's also the chance that the owner of a tiny URL might update it differently on each side of the partition. In that case, now you are randomly serving one of them to clients. The owner knows what they did and it's their own fault. It's still better than serving neither.

So, it appears that availability is more important than consistency for this application - just by using common sense.

许可以下: CC-BY-SA归因
scroll top