Effective date ranges for ISO 3166 content
Overview
Add temporal validity to ISO 3166 subdivision data to handle historical changes in country subdivisions.Problem
Currently, the ISO 3166 content has a simple unique constraint:- Historical subdivision changes (e.g., state name changes)
- Subdivision mergers or splits
- Temporal queries (e.g., “What was the state code in 2020?”)
Proposed solution
Addeffective_start_date and effective_end_date columns to track when a subdivision record is valid.
Schema changes
Example data
API changes
Ingestion endpoint
Update the ingestion endpoint to accept date ranges:effective_start_dateis requiredeffective_end_dateis optional (NULL means “still valid”)effective_end_datemust be aftereffective_start_date- Date ranges cannot overlap for the same (country_code, subdivision_code)
Geocoding endpoint
The geocoding endpoint behavior: Default behavior (no date specified):- Use the current date
- Return the subdivision valid today
Migration strategy
- Add columns with default values (non-breaking)
- Populate existing data with default dates
- Update application code to use date ranges
- Update ingestion endpoint to accept dates
- Drop old constraint and add new one
- Deploy with backward compatibility
Benefits
- Historical accuracy: Track subdivision changes over time
- Temporal queries: Query data as of a specific date
- Audit trail: Know when subdivisions changed
- Compliance: Meet regulatory requirements for historical data
Implementation checklist
- Design database schema changes
- Write migration script
- Update DTO for ingestion endpoint
- Update validation logic
- Update service layer to query by date
- Add tests for date range logic
- Update documentation
- Deploy to staging
- Test with historical data
- Deploy to production
Estimated effort
- Database changes: 2 days
- Application changes: 3 days
- Testing: 2 days
- Documentation: 1 day
- Total: ~2 weeks
Other planned features
1. Batch geocoding
Description: Allow geocoding multiple addresses in a single request. Benefits:- Reduced API calls
- Better performance for bulk operations
- Lower latency
2. Address validation
Description: Validate addresses without geocoding. Benefits:- Faster than full geocoding
- Lower cost (no Google API call)
- Useful for form validation
3. Reverse geocoding
Description: Convert coordinates to addresses. API design:4. Cache management
Description: Admin endpoints to manage the geocoding cache. Endpoints:DELETE /api/v1/internal/cache/{address}- Clear specific cache entryDELETE /api/v1/internal/cache- Clear all cacheGET /api/v1/internal/cache/stats- Cache statistics
5. Rate limiting
Description: Implement rate limiting per API key. Benefits:- Prevent abuse
- Fair usage
- Cost control
- Use Redis for distributed rate limiting
- Configure limits per API key
- Return 429 Too Many Requests when exceeded
6. Webhook notifications
Description: Notify external systems when content is updated. Use case: Automatically sync ISO 3166 changes to other services. Implementation:- Store webhook URLs in database
- Trigger webhooks on content ingestion
- Retry failed webhooks
Contributing to future features
If you’d like to implement any of these features:- Create an issue on GitHub describing your approach
- Get approval from the team
- Follow the contribution guide for implementation
- Write comprehensive tests
- Update documentation
- Submit a pull request