Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Cloning Internet Applications with Ruby

You're reading from   Cloning Internet Applications with Ruby Make clones of some of the best applications on the Web using the dynamic and object-oriented features of Ruby

Arrow left icon
Product type Paperback
Published in Aug 2010
Publisher Packt
ISBN-13 9781849511063
Length 336 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Chang Sau Sheong Chang Sau Sheong
Author Profile Icon Chang Sau Sheong
Chang Sau Sheong
Arrow right icon
View More author details
Toc

Designing the clone


Cloning TinyURL is relatively simple but there is some thought behind the design of the application. We will be building a clone of TinyURL called Tinyclone, which will be hosted at the domain http://tinyclone.saush.com.

Creating a short URL for each long URL

The domain of the short URL is fixed. What's left is the file pathname. We need to represent the long URL with a unique file pathname (a key), one for each long URL. This means we need to persist the relationship between the key and the URL.

One of the ways we can associate the long URL with a unique key is to hash the long URL and use the resulting hash as the unique key. However, the resulting hash might be long and hashing functions could be slow.

The faster and easier way is to use a relational database's auto-incremented row ID as the unique key. The database will help ensure the uniqueness of the ID. However, the running row ID number is base 10. To represent a million URLs would already require seven characters...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image