I’m building a small tool for running Instagram giveaways in a more structured and transparent way.
The idea is simple: paste an Instagram post or Reel, configure the giveaway rules, analyze the comments, and select winners.
The interesting part was not the random winner selection. The harder part was getting Instagram data reliably and doing it without wasting API requests.
What I built
The app currently lets a user:
paste an Instagram post or Reel URL
inspect the publication
configure giveaway rules
require a minimum number of mentions
count one entry per comment or per user
exclude accounts
select multiple winners
generate a verification code for the giveaway
My stack is:
React
Node.js
Express
Mercado Pago
HikerAPI for Instagram data
I’m using HikerAPI as the main Instagram data source.
The first architecture was wasteful
My original flow looked like this:
Instagram URL
↓
Fetch all comments
↓
Analyze participants
↓
Calculate price
↓
Payment
↓
Run giveaway
That worked technically, but there was an obvious business problem.
If someone pasted a post with 2,000 or 3,000 comments, I could spend a large number of API requests downloading those comments.
If that person never paid or never completed the giveaway, I still paid for those API calls.
So I changed the architecture.
Metadata first, comments later
The new flow looks like this:
Instagram URL
↓
Fetch only post metadata
↓
Read comment_count
↓
Calculate pricing tier
↓
Payment if required
↓
Fetch comments
↓
Filter valid entries
↓
Select winner
This means I only make a small metadata request before payment.
The expensive part — retrieving all comments — happens only after the giveaway is authorized.
For free giveaways, I absorb the API cost.
For paid giveaways, the user pays first.
That change made much more sense for a usage-based API.
A basic HikerAPI request
Here is a simple Python example for fetching a user and their stories:
import requests
headers = {
“x-access-key”: “YOUR_KEY”
}
user = requests.get(
“https://api.hikerapi.com/v2/user/by/username?username=9gag“,
headers=headers
).json()
resp = requests.get(
f”https://api.hikerapi.com/v2/user/stories?user_id={user[‘pk’]}“,
headers=headers
)
print(resp.json())
In my project I’m using Node.js instead of Python, but the idea is the same: use the REST API to retrieve only the Instagram data I need.
Pricing based on post metadata
Right now I use the Instagram-reported comment count to determine the giveaway price.
For example:
0–300 comments
FREE
301–999 comments
$2,000 ARS
1,000–1,999 comments
$3,500 ARS
2,000–3,000 comments
$5,000 ARS
The important detail is that I don’t need to download every comment to determine that price.
I can get the publication metadata first and decide whether payment is required.
Something harder than expected: comment counts
One issue I didn’t expect was that the comment count shown by Instagram does not always match the number of top-level comments I eventually retrieve.
Replies can affect the displayed count.
For the giveaway itself, I’m mainly interested in top-level comments because those are the actual giveaway entries.
So I currently use:
Instagram comment_count
→ pricing
Top-level comments retrieved
→ participants
That separation keeps the pricing predictable while keeping the giveaway logic cleaner.
Pagination was another challenge
Retrieving a few comments is easy.
Retrieving hundreds or thousands means dealing with pagination, duplicate comments, repeated cursors, partial responses, and cases where an API says there is another page but the next request returns no useful data.
I ended up adding protections such as:
if (commentsMap.has(comment.id)) {
continue;
}
and cursor tracking:
if (
nextCursor === currentCursor ||
usedCursors.has(nextCursor)
) {
throw new Error(“PAGINATION_CURSOR_REPEATED”);
}
That helped prevent infinite loops and duplicated giveaway entries.
Payment validation happens on the backend
Another thing I wanted to avoid was trusting the frontend.
The frontend can say:
Payment approved
but the backend still verifies the payment directly before allowing the expensive comment retrieval.
The backend validates:
payment status
payment amount
external reference
whether the payment was already used
Only after that validation does the system retrieve the comments and run the giveaway.
What I’m working on next
I’m still improving a few parts:
better pagination handling
caching comment results
fallback providers
usage and API cost tracking
handling larger giveaways
better verification pages for completed giveaways
The project started as a relatively simple “pick a random Instagram comment” tool, but the interesting engineering problems turned out to be API cost control, pagination, payment validation, and making the giveaway reproducible.
If you’ve built something using Instagram APIs or usage-based APIs, I’d be interested to know how you handle API costs before a customer commits to an action.
Suggested Dev.to tags: