Ravi Sir's Cards › AWS
Why 302 and ADD clicks?
This revision card explains Why 302 and ADD clicks? It starts from the need that returning 200 with the URL in JSON forces every client to invent redirect logic. Browsers already follow Location. It describes HTTP 302 Found with a Location header is the classic shortener response. ADD on clicks is an atomic DynamoDB increment under concurrent hits. The how-to section notes in Lambda — GetItem by shortCode , then UpdateItem ADD clicks :1 , then return statusCode 302 and headers Location = longUrl. An example on the card is two phones open /Ab12XyZ at once; both redirect and clicks becomes 2, not a lost update.
Read card text
What this card says
Why do we need it?
Returning 200 with the URL in JSON forces every client to invent redirect logic. Browsers already follow Location.
What is it?
HTTP 302 Found with a Location header is the classic shortener response. ADD on clicks is an atomic DynamoDB increment under concurrent hits.
How to do it
In Lambda: GetItem by shortCode → UpdateItem ADD clicks :1 → return statusCode 302 and headers Location = longUrl.
statusCode: 302
Example
Two phones open /Ab12XyZ at once; both redirect and clicks becomes 2, not a lost update.