You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We also need to consider takeover attacks where an attacker takes a `short_url` that is similar to another
55
102
short one in order to trick unsuspecting users (ex: `example` and `Example`). We can achieve this by only
56
103
allowing custom slugs to be lower case. The reason not to down case incoming slugs is that it would both increase
57
-
our computation time, doing the actual down case, and it would reduce our available characters by 26.
104
+
our computation time, doing the down case on every request, and it would reduce our available characters by 26.
58
105
59
106
Another approach would be to do the lookup by a `short_url` as given, and if it misses in the database, try
60
107
again after down casing. This would work and maintain our full character set, but it would violate our first
61
108
consideration - keep this route fast. In order to maintain speed, we should also avoid running multiple SQL queries to determine the `full_url`. This is done by not allowing users to enter custom slugs with upper case letters so a down case is not necessary as a second query.
62
109
110
+
#### Scale
111
+
112
+
The final consideration is how this design will scale. The product requirements give no bound to the scale of
113
+
the application. This means the design must strike a balance between speed of development, complexity of the
114
+
solution and potential future scaling.
115
+
116
+
Based on 65 possible characters and a default of six characters for a random short, there are
117
+
75.4 billion possible shorts.
118
+
119
+
```math
120
+
65^5 = 75,418,890,625
121
+
```
122
+
123
+
This provides the balance between available options and our choice of data store, PostgreSQL.
124
+
125
+
While the read may be fast, we should also consider the speed of the create. If we only randomly generate
126
+
a code and then check to ensure it's not taken, we will slow down dramatically as the number of shorts grow.
127
+
Said another way, the naive approach to code generation is `O(n)` for `n` existing shorts.
128
+
An ideal solution would be able to generate a random that's in order `O(1)`. This is an optimization that
129
+
we will aim to develop in the future.
130
+
63
131
## Project Design
64
132
65
133
This section outlines aspects of the application design that relate to the project requirements.
@@ -68,14 +136,22 @@ This section outlines aspects of the application design that relate to the proje
0 commit comments