Our file metadata generation follows a hybrid approach that leverages the strengths of both the Upload and Storage services while maintaining flexibility and security.
-
Collaborative Metadata Generation
- Upload service prepares initial metadata
- Storage service validates and completes metadata
- Consistent ID generation across services
-
Metadata Lifecycle
- Generate preliminary upload ID
- Capture initial file information
- Original filename
- File size
- Initial upload timestamp
- User ID (if available)
- Validate or generate secure file ID
- Determine final storage path
- Ensure all metadata fields are complete
- Persist metadata in storage system
- Cryptographically secure
- Globally unique
- URL-safe
- Unpredictable
- Use cryptographically secure random number generator
- Generate 32 bytes of random data
- Encode using base64 URL-safe encoding
func generateSecureFileID() (string, error) {
randomBytes := make([]byte, 32)
_, err := rand.Read(randomBytes)
if err != nil {
return "", err
}
return base64.URLEncoding.EncodeToString(randomBytes), nil
}- Distributed ID generation (e.g., Snowflake algorithm)
- Enhanced collision detection
- Configurable ID generation strategies
- Never expose raw ID generation mechanism
- Use cryptographically secure random sources
- Implement rate limiting on ID generation
- Validate IDs before storage
- Flexible metadata completion
- Clear service responsibilities
- Secure ID generation
- Minimal proto contract changes
- Slightly more complex implementation
- Potential for minor performance overhead
// Upload Service
func PrepareUpload(req *PrepareUploadRequest) {
// Generate preliminary metadata
// Partial information only
}
// Storage Service
func CompleteUpload(req *CompleteUploadRequest) {
// Validate and complete metadata
// Generate/validate file ID
// Finalize storage path
}- Log metadata generation events
- Track ID generation success/failure rates
- Monitor metadata completion latency
- Investigate distributed ID generation strategies
- Explore potential performance optimizations
- Develop comprehensive testing for ID generation