admin管理员组文章数量:1394610
I am developing a web application and want to implement base36-encoded IDs for URLs, similar to Reddit's approach (e.g., reddit/r/programming/comments/1jkgh2s/ where 1jkgh2s is the base36-encoded ID).
For efficiency, I plan to store IDs as integers in the database. However, I'm unsure which architectural layer should be responsible for the base36 encoding/decoding:
Presentation Layer: Convert in HTTP handlers
- Store IDs as integers in database
- Use integer IDs in domain model
- Convert between integer and base36 when encoding/decoding URLs
Application Layer: Convert in services
- Store IDs as integers in database
- Use integer IDs in domain model
- Convert between integer and base36 when interacting with lower layers (domain and infrastructure)
- Presentation and application layers use base36 IDs, all other layers use integer IDs
Domain Layer: Convert in domain model
- Store IDs as integers in database
- Use base36 IDs in domain model
- Convert between integer and base36 when hydrating domain objects
- All layers use base36 IDs
Infrastructure Layer: Convert in data access
- Store IDs as integers in database
- Use base36 IDs in domain model
- Convert between integer and base36 during data retrieval
- All layers use base36 IDs
Approaches 2, 3, and 4 provide consistent base36 ID contract for all presentation layers (Web, API, CLI).
Additional context:
- Planning to add more interfaces (e.g., RESTful API, CLI) in the future
- Deliberately choosing not to use UUIDs in favor of shorter, more human-friendly identifiers
- Aware of the security implications of using auto-incrementing IDs (whether encoded in base36 or not) and have accepted these trade-offs
Key Questions:
- Which layer is most appropriate for this responsibility?
- Should all interfaces (Web, API, CLI) use base36 IDs for consistency?
- If all interfaces should use base36, does this suggest it belongs in the domain layer?
I am developing a web application and want to implement base36-encoded IDs for URLs, similar to Reddit's approach (e.g., reddit/r/programming/comments/1jkgh2s/ where 1jkgh2s is the base36-encoded ID).
For efficiency, I plan to store IDs as integers in the database. However, I'm unsure which architectural layer should be responsible for the base36 encoding/decoding:
Presentation Layer: Convert in HTTP handlers
- Store IDs as integers in database
- Use integer IDs in domain model
- Convert between integer and base36 when encoding/decoding URLs
Application Layer: Convert in services
- Store IDs as integers in database
- Use integer IDs in domain model
- Convert between integer and base36 when interacting with lower layers (domain and infrastructure)
- Presentation and application layers use base36 IDs, all other layers use integer IDs
Domain Layer: Convert in domain model
- Store IDs as integers in database
- Use base36 IDs in domain model
- Convert between integer and base36 when hydrating domain objects
- All layers use base36 IDs
Infrastructure Layer: Convert in data access
- Store IDs as integers in database
- Use base36 IDs in domain model
- Convert between integer and base36 during data retrieval
- All layers use base36 IDs
Approaches 2, 3, and 4 provide consistent base36 ID contract for all presentation layers (Web, API, CLI).
Additional context:
- Planning to add more interfaces (e.g., RESTful API, CLI) in the future
- Deliberately choosing not to use UUIDs in favor of shorter, more human-friendly identifiers
- Aware of the security implications of using auto-incrementing IDs (whether encoded in base36 or not) and have accepted these trade-offs
Key Questions:
- Which layer is most appropriate for this responsibility?
- Should all interfaces (Web, API, CLI) use base36 IDs for consistency?
- If all interfaces should use base36, does this suggest it belongs in the domain layer?
1 Answer
Reset to default 1In a web application, base436 ID conversion is typically handled in the presentation layer. This is where integer IDs are encoded or decoded for a URL-friendly representation. This approach maintains internal consistency with integer IDs while presenting user-friendly URLs. However, the optimal layer may vary based on specific architectural requirements and design preferences.
本文标签: encodingWhich component or layer should be responsible for base36 ID conversionStack Overflow
版权声明:本文标题:encoding - Which component or layer should be responsible for base36 ID conversion? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744093913a2589930.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论