em có cột ID đơn hàng, ví dụ như amazon 1 ngày toàn thế giới rất nhiều đơn hàng, vậy họ gen ID thế nào để toàn bộ số đơn hàng k bị trùng nhau ạ, có nên dùng thuật toán snowflake để gen k ạ, ưu và nhược điểm của snowflake là gì vậy ạ
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Anh không rõ là amazon làm thế nào, nhưng nếu em dùng MySQL hay các hệ quản trị cơ sở dữ liệu khác đều có auto increment id em ạ, như vậy là đủ rồi.
Nếu không dùng auto increment thì sử dụng uuid cũng là một lựa chọn đơn giản như MongoDB vẫn đang làm em ạ.
vâng ạ, nhưng nếu cứ tăng id từ 1 -> 1 tỷ k ổn được anh ạ. Ví dụ 1 ngày 10 triệu đơn đơn thì 1 năm là 3 65 triệu đơn, chi cần vài năm là id bị tràn số thôi
Anh nghĩ là thoải mái với bigint em ạ: https://dev.mysql.com/doc/refman/8.0/en/integer-types.html
Em thấy có một bài viết nó cũng giống như cái a thắc mắc. Anh xem bài viết này xem có đúng không ạ? Nó đưa ra những cách tạo id và ưu nhược điểm của nó ạ.