url-shortner's People
url-shortner's Issues
Build out DELETE /api/urls/:id
Build out PUT /api/urls/:id
Allow the url
field to be changed. Because (account_id, url)
is unique, we'll need to check for an existing url
before we update.
TBD: When a url is changed, should we reset visit_count
and delete the visit records?
Build out GET /api/urls
Build out production infrastructure
Terraform all AWS components:
- IAM
- VPC
- ECS Fargate
- RDS
- SQS
- Elasticache
Build out /:slug
- Insert a
visits
record - Increment
url.visit_count
- 302 to the destination url
We should be careful when incrementing url.visit_count
. Write the SQL to perform the update atomically:
update visit_count = visit_count + 1 where id = ?
Use SQS to perform analytic work in the background
Move insertion of visits
and incrementing visit_count
to a background script that consumes an SQS message that will be queued when a url is visited.
Build out GET /api/urls/:id
Let :id
be the id
or slug
Build custom middleware to perform API authentication.
See: https://echo.labstack.com/cookbook/middleware/
Look for X-API-Key
in the header and then lookup the api key in the accounts
table. Pass the account struct on the request context.
Create schema
Build out the following schema. Let's use https://github.com/rubenv/sql-migrate to handle migrations.
Place Memcache in front of the lookup-by-slug query
Build out request fingerprinting so that we can determine unique visits
Should we use a cookie? For now let's not (avoid GDPR?). Instead, store a fingerprint (hash) of soem request metadata: UserAgent + IP?
Build production Docker image
Use multi-stage build to place a static Go binary on a scratch image
Build out /api/urls/:id/analytics
- Should support date filtering:
start
,end
- Allow date sorting direction
?sort=asc|desc
- Don't worry about paging for now
Response should look something like:
{
total_visits: 2344,
total_unique: 1567,
visits: [
{
date: '2020-04-26'
total: 345,
unique: 298
},
...
]
}
Queries look something like:
Total:
select date(created_at) as d, count(*) from visits where created_at >= $start and created <= $end group by d
Unique:
select date(created_at) as d, count(unique(vistor_fingerprint)) from visits where created_at >= $start and created <= $end group by d
Implement a deployment script
Build docker image + push to ECR + update ECS service definition
Implement dev environment with docker compose
Stub out a working scaffold of the tech stack with Docker Compose. Containers needed:
Build out POST /api/urls
The biggest concern here is generating the shortened slug that's going to be used in the URL. After a bit of research, it looks like base64
or base62
encoding the id is a tried and true method:
https://stackoverflow.com/questions/2375968/url-shortener-best-encoding-method
Found a Go library that does the encoding and swaps chars into url encodable values: https://github.com/lytics/base62
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.