Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 블로그 서비스 최적화
- 자바스크립트 딥다이브
- 학습내용정리
- js pattern
- 자바스크립트 패턴
- js pattern
- DOM
- 이벤트
- 진행기록
- 자바스크립트
- peerdependencies
- package management
- 브라우저의 렌더링 과정
- middleware pattern
- mixin pattern
- 새 코드 받아오기
- 스코프
- 딥다이브
- 제너레이터와 async/await
- unique identifiers
- 커리어
- 프론트엔드 성능 최적화 가이드
- 이미지 갤러리 최적화
- pr review
- 올림픽 통계 서비스 최적화
- 프로그래머스
- version management
- Babel과 Webpack
- const
- 모던 자바스크립트 Deep Dive
Archives
- Today
- Total
Dev Blog
Unique Identifiers 본문
Unique Identifiers: Overview, Pros, Cons, and Best Practices
Unique identifiers are crucial for ensuring uniqueness, reducing collision probability, and enabling easy tracking in various systems. Below is a summary of common identifier types:
1. UID (Unique Identifier)
- Description: General term for any unique identifier, often implemented as an incremental integer, hash, or other ID type.
- Common Uses: Database primary keys, legacy systems.
- Pros:
- Simple to implement and easy to read (e.g., sequential numbers).
- Easy to query and index in relational databases.
- Cons:
- Collisions possible if improperly managed.
- Sequential IDs can expose system usage details.
- Best Practices:
- Avoid in distributed systems without a centralized authority.
- Use for internal systems or predictable cases without security concerns.
2. UUID (Universally Unique Identifier)
- Description: A 128-bit identifier standardized by RFC 4122, often versioned (e.g., UUID v4 for random generation).
- Common Uses: Database keys, distributed systems, software product keys.
- Pros:
- Universal across programming languages and systems.
- Large range minimizes collision probability.
- Cons:
- Long (36 characters), impacting database indexing performance.
- Non-sequential, unsuitable for ordered lists.
- Best Practices:
- Use UUID v4 for general purposes, v1 for time-based order.
- Avoid for high-performance primary keys in relational databases.
3. GUID (Globally Unique Identifier)
- Description: A Microsoft-specific implementation of UUIDs.
- Common Uses: Windows registry, COM programming, Microsoft systems.
- Pros:
- Interoperable with UUIDs.
- Standard for .NET applications.
- Cons:
- Platform-dependent and not distinct from UUIDs outside Microsoft systems.
- Best Practices:
- Use in Microsoft or .NET environments where GUIDs are standard.
4. CUID (Collision-Resistant Unique Identifier)
- Description: Compact, collision-resistant ID for distributed systems.
- Common Uses: URLs, distributed databases, session IDs.
- Pros:
- Shorter and URL-friendly.
- Reduced collision probability due to structured algorithm.
- Cons:
- Less universally supported.
- Not fully collision-proof in high-scale systems.
- Best Practices:
- Ideal for frontend-heavy apps, distributed systems, and URL-safe IDs.
5. Nano ID
- Description: Compact, customizable, URL-friendly ID based on randomness.
- Common Uses: URL slugs, client-side identifiers, short-lived unique IDs.
- Pros:
- Extremely small (21 characters by default) and fast to generate.
- Highly customizable in length and character sets.
- Cons:
- No timestamping for chronological tracking.
- Customization may require additional work.
- Best Practices:
- Use for short, unique frontend or URL-safe IDs.
- Customize for specific uniqueness or constraints.
Additional Unique Identifier Types
1. Snowflake ID (Twitter Snowflake)
- Description: A distributed, 64-bit, time-based identifier combining timestamp, machine ID, and a sequence number.
- Pros:
- Compact and scalable.
- Ordered for chronological sorting.
- Cons:
- Requires machine IDs and server clock accuracy.
- Best Practices:
- Ideal for distributed systems needing time-order (e.g., social media posts).
2. KSUID (K-Sortable Unique Identifier)
- Description: Time-based identifier designed to be k-sortable and UUID-like.
- Pros:
- Encodes a timestamp for ordered IDs.
- No need for centralized databases in distributed systems.
- Cons:
- Longer (27 characters), increasing storage or bandwidth use.
- Best Practices:
- Use for distributed systems requiring time-order and uniqueness (e.g., event logs).
3. ObjectId (MongoDB)
- Description: A 12-byte identifier combining timestamp, machine, process, and a counter.
- Pros:
- Shorter than UUIDs and naturally time-ordered.
- Cons:
- MongoDB-specific format may need adaptation elsewhere.
- Best Practices:
- Ideal for MongoDB or document-based databases.
Summary Comparison
Recommendations for Choosing the Right Identifier
- Distributed Systems: Use UUIDs, CUIDs, or Snowflake IDs.
- URLs/User-Friendly IDs: Nano ID or CUID for compact and URL-safe options.
- Database Keys: Avoid UUIDs for primary keys due to indexing costs; consider CUIDs or Snowflake IDs for compactness and order.
'Development Notes > Terminology and Concepts' 카테고리의 다른 글
쿠키🍪_Cookie (0) | 2025.02.07 |
---|---|
리스코프 치환 원칙(Liskov substitution principle) (0) | 2024.12.08 |
에러와 버그의 차이점 (0) | 2024.12.08 |
peerDependencies 와 overrides 의 차이점(package management) (0) | 2024.11.09 |
DOM 트리의 탐색 (0) | 2022.12.13 |
Comments