Cheapest number wins
- Next.js
- TypeScript
- Go
- gRPC
- Postgres
- Pusher
A lot of sites won't send a verification code to a VoIP number. If you need a real, non-VoIP number for a one-time code, you end up on a handful of provider sites, each with its own balance, its own prices, and its own stock. The same number for the same service can cost twice as much on one site as on another, and the cheap site might be out of stock in the country you need.
AlteraSMS puts all of them behind one dashboard. You pick a service and a country, it finds the cheapest provider that has a number right now, and you get the code in the same window. One balance, one interface.
The backend is a Go gRPC server on Postgres. The dashboard is Next.js, and there's also a Discord bot in Python that talks to the same gRPC services, so you can get a number without opening the site.
Picking a provider
Every provider does roughly the same four things: list what it has, quote a price, sell a number, and cancel one. Each one gets an adapter behind a single interface:
type Provider interface {
Name() string
Quote(service, country string) (*Quote, error) // price in cents + stock
Order(service, country string) (*SMSOrder, error)
Cancel(orderID string) (*CancelOrderResponse, error)
}
When someone orders a number, the server asks every provider for a quote at once, drops the ones that are out of stock or don't carry that service in that country, and orders from the cheapest:
func CreateOrder(service, country string) (*SMSOrder, error) {
quotes := quoteAll(service, country) // all providers in parallel, with a timeout
sort.Slice(quotes, func(i, j int) bool {
return quotes[i].CostInCents < quotes[j].CostInCents
})
for _, q := range quotes {
order, err := q.Provider.Order(service, country)
if err == nil && order.Type == "" {
order.Provider = q.Provider.Name()
return order, nil
}
// Sold out between the quote and the order: try the next cheapest
}
return nil, ErrOutOfStock
}
Quotes go stale fast. A provider can say it has stock and then sell its last number before our order lands. So the server doesn't trust a single quote: if the cheapest order fails, it falls through to the next cheapest. The customer only sees "out of stock" when every provider has failed.
The provider that sold the number is saved on the order. Cancelling, and matching the incoming code to the right number, both have to go back to that same provider.
The same comparison runs before anyone buys. When you pick a service, the dashboard lists the countries it's available in, each with the lowest price across all providers. So the price you see is the price you'll get, not one provider's price.
Pricing
Providers quote what a number costs us. The customer price is that cost with a markup, but never less than a fixed margin:
numberPrice := max(
int64(order.CostInCents+25),
int64(float64(order.CostInCents)*common.SMSPriceMultiplier),
)
On cheap numbers a percentage markup comes out to a fraction of a cent, so there's a 25¢ floor. On expensive ones the multiplier takes over. The multiplier is an environment variable, so pricing can change without a deploy. Partner accounts get a discount on top.
Because the markup is applied after picking the cheapest provider, the customer's price follows whichever provider is cheapest that minute. When providers compete, the customer saves.
Pay when the code arrives
The balance isn't charged when you get a number. It's charged when the code shows up.
Ordering a number reserves it. The server checks that your balance covers it plus every other number you're still waiting on, so you can't open more orders than you could pay for. When the provider receives the SMS, it calls a webhook. That's when the price comes off the balance, in the same database transaction that saves the code and marks the number received:
db.WithTx(func(tx *db.Database) error {
num.User.Balance -= num.Price
if err := tx.Users.Update(&num.User); err != nil {
return err
}
num.Status = db.NumberReceivedStatus
num.Code = sql.NullString{String: body.SMS, Valid: true}
return tx.Numbers.Update(num)
})
If the code never comes, you don't pay. Every number has an expiration from the provider, and the server keeps a timer per waiting number. When it fires, the number is deleted and the reserved amount is free again. The timers live in memory, so on startup the server reloads every waiting number from the database and schedules it again. A restart doesn't leave numbers stuck reserving your balance.
You can also cancel a number yourself before a code arrives, and the cancellation goes to whichever provider sold it.
Live updates
The dashboard never polls. When a number is ordered, receives its code, expires, or is cancelled, the server pushes the change over Pusher to a channel for each of your active sessions. The code shows up on screen the moment the provider's webhook lands. Deposits and notifications work the same way.
Deposits
Balance comes in through Stripe, PayPal, or NOWPayments for crypto. Each has its own webhook, and each one checks the provider's signature before doing anything. A webhook for an invoice that's already paid is ignored, so a provider retrying an event can't credit the same deposit twice. Crediting the balance and marking the invoice paid happen in one transaction.
A first deposit from someone with a linked Discord account also gives them the verified and customer roles in the AlteraSMS Discord server.
Accounts
Sign-in supports a password, Discord OAuth, and passkeys. Two-factor works with TOTP apps, passkeys, or one-time backup codes. Sessions are listed in settings and can be revoked one at a time. Forms are CSRF-protected, and the dashboard only talks to the Go server from the server side, so the gRPC API is never exposed to the browser.
What this gets you
One balance and one form, no matter how many providers are behind it. Every order goes to the cheapest provider that actually has a number, falls through to the next one if that fails, and only costs you anything once the code is on your screen.