Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8396679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:36:02+00:00 2026-06-09T20:36:02+00:00

In my db scheme, I need a autoincrement primary key. How I can realize

  • 0

In my db scheme, I need a autoincrement primary key. How I can realize this feature?

PS For access to DynamoDB, I use dynode, module for Node.js.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T20:36:04+00:00Added an answer on June 9, 2026 at 8:36 pm

    Disclaimer: I am the maintainer of the Dynamodb-mapper project

    Intuitive workflow of an auto-increment key:

    1. get the last counter position
    2. add 1
    3. use the new number as the index of the object
    4. save the new counter value
    5. save the object

    This is just to explain the underlying idea. Never do it this way because it’s not atomic. Under certain workload, you may allocate the same ID to 2+ different objects because it’s not atomic. This would result in a data loss.

    The solution is to use the atomic ADD operation along with ALL_NEW of UpdateItem:

    1. atomically generate an ID
    2. use the new number as the index of the object
    3. save the object

    In the worst case scenario, the application crashes before the object is saved but never risk to allocate the same ID twice.

    There is one remaining problem: where to store the last ID value ? We chose:

    {
        "hash_key"=-1, #0 was judged too risky as it is the default value for integers.
        "__max_hash_key__y"=N
    }
    

    Of course, to work reliably, all applications inserting data MUST be aware of this system otherwise you might (again) overwrite data.

    the last step is to automate the process. For example:

    When hash_key is 0:
        atomically_allocate_ID()
    actual_save()
    

    For implementation details (Python, sorry), see https://bitbucket.org/Ludia/dynamodb-mapper/src/8173d0e8b55d/dynamodb_mapper/model.py#cl-67

    To tell you the truth, my company does not use it in production because, most of the time it is better to find another key like, for the user, an ID, for a transaction, a datetime, …

    I wrote some examples in dynamodb-mapper’s documentation and it can easily be extrapolate to Node.JS

    If you have any question, feel free to ask.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need use this framework with IOS 4.3 Scheme, How can i do this?
Before running integration tests I need to setup database. This include generating SQL-scheme (based
I have this schema which I need to define two primary keys; one is
Using scheme I have the need to use the following function. (All args are
I need to create a custom URI scheme for my project. i.e urn:myprotocol:{p1}:{p2}:{p3}:{p4} -
I need to come up with a naming scheme for the situation where some
I have this schema which I need to match 2 rows from user_data :
I need to ignore routes matching this schema /{controller}/edit/undefined {controller} - could be any
I need to execute this query to find out the next auto_increment value that
Due to an absurd SOAP authentication scheme I need to md5 hash an API

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.