Prompt
I'm building an ecommerce platform and need tax rates by address in milliseconds
Latest observation
To get tax rates by address in milliseconds, you’ll want a design that avoids doing tax logic on every request and instead uses address normalization + geocoding + precomputed jurisdiction lookup with aggressive caching.
Recommended approach
1) Normalize the address first
Before looking up tax, standardize the address:
- street abbreviation handling
- ZIP+4 if available
- apartment/unit stripping or preservation rules
- casing/spacing normalization
This improves cache hits and lookup accuracy.
2) Convert the address to a jurisdiction key
Tax is usually based on:
- country
- state/province
- county/district
- city
- special tax districts / sales tax jurisdictions
- postal code in some regions
The fastest method is usually:
- address → latitude/longitude via geocoding
- lat/lon → tax jurisdiction using a spatial index or jurisdiction boundary dataset
- return cached tax rate for that jurisdiction
3) Use a two-layer cache
For millisecond performance:
- L1 in-memory cache in your app instance for hot addresses
- L2 distributed cache like Redis for cross-instance reuse
Cache keys should be based on a normalized address or jurisdiction identifier:
tax:addr:{normalized_hash}tax:jurisdiction:{geo_hash}
4) Precompute tax rates by jurisdiction
Don’t calculate from scratch on each request. Store:
- combined rate
- state rate
- local rate
- special district rate
- validity dates / effective date
If your business needs exact product taxation, also store:
- taxability rules by product category
- exemptions
- destination vs origin sourcing rules
5) Keep boundary data up to date
Tax rates change frequently, so you need:
- versioned rate tables
- effective date ranges
- scheduled refresh jobs
- rollback support
6) Consider a dedicated tax service
If you need speed plus compliance, build or use a service that:
- exposes
GET /tax-rate?address=... - returns
rate,jurisdiction,confidence,source,effective_date - is backed by cached jurisdiction maps
This keeps tax logic out of checkout code.
Fast architecture example
Checkout request
- User enters address
- Normalize address
- Check L1 cache
- If miss, check Redis
- If miss, geocode
- Lookup jurisdiction in spatial index
- Fetch rate from precomputed table
- Cache result
- Return tax rate
Target latency:
- L1 hit: sub-millisecond to a few ms
- Redis hit: ~1–5 ms depending on deployment
- geocode + lookup: typically slower, so keep it off the critical path when possible
Best practices for millisecond latency
- Use a local embedded map of jurisdiction boundaries if possible
- Cache by postal code + street and by lat/lon
- Warm the cache with popular addresses
- Use async refresh for expiring rates
- Avoid calling external APIs synchronously during checkout unless necessary
- Index jurisdiction polygons with a spatial database or geospatial library
If you want the simplest viable solution
If you don’t need to build this from scratch:
- use a tax API provider
- still add your own caching layer in front
- cache responses for normalized addresses
- refresh periodically
Data model suggestion
{
"normalized_address": "123 MAIN ST APT 4, AUSTIN, TX 78701",
"jurisdiction_id": "TX-AUSTIN-001",
"lat": 30.2672,
"lon": -97.7431,
"rates": {
"state": 0.0625,
"local": 0.0125,
"special": 0.0050,
"total": 0.0800
},
"effective_from": "2026-01-01",
"effective_to": null
}
If you want, I can help you design:
- a low-latency tax lookup architecture,
- a Redis cache strategy, or
- an API schema for tax-by-address.
Brands