How to choose in msgpack, list and map?

I have a complex object like this: class myobject{ int id, int level, string desc // max length = 400 }

need to save List as a bin, and i have three choices:

  1. json and msgpack
  2. store it as Dictionary<int, List>, which id as dictionary key, and the value of dictionary is [level, desc]
  3. store it as List<List>, a list of [id, level, desc]

my question is which one is the best, and why? thank you.

It depends on how you’re going to be accessing the data:

  1. Serializing into JSON and storing in a single string bin would be the easiest to deal with. JSON is universal so you can read/write it from any application, however you wont be able to easily manipulate the individual elements within Aerospike (like Lua UDFs).

  2. If you need more precise control or want to use Lua code on Aerospike, then you can store the objects using the list and map datatypes. You can use a List bin containing a separate Map for each object. This takes more work in translating your object but you can then your own logic in the database to query and manipulate the data without your application involved.

thank you. its very helpful. can you tell me more how about the performance differences?

There’s not much difference here, at least with Aerospike. The database just stores whatever you send it.

Choose the format that gives you the functionality you want first because there probably isn’t any real performance impact. JSON might be a little faster to serialize into a string than building out the list and map but you will have to test and see what the impact is.