Max size of User and Venue Ids - foursquare

As a side project I am creating a connected app and was wondering what the max size for the user and venue ids were? Should I just do 'BIGINT UNSIGNED NOT NULL' for user ids and 'VARBINARY(255)' for venue ids?

Yes, those both work. User IDs are 64-bit longs, and VARBINARY(255) will be sufficient for venue ids.

Related

Need idea on how to query dynamo db for specific date range in node

Need to design a table in Dynamo DB to get the month-wise data like how many users logged in to the application on a particular time frame as below
Today how many users logged in?
Particular month how many users logged in?
3 Particular year how many users logged in?
I am using node js in lambda with dynamo DB. Need help with table design and how to use filter to get the data for the above requirement.
Thanks in advance
If your user items are small, a single query for users can return ~5,000 items (all your users). If you run this every 10 minutes, your monthly on-demand cost is $0.12.
Just query all the users and calculate the metrics on the server, it's not worth the time to design anything more complex.

Best practice of creating a 100K elements in a Set collection in Java

Creating an Injector application for Elasticsearch to do performance testing on a project I'm working on. I have users and each user has activities per day, an activity can be making/receiving a phone call, doing a meeting, sending/receiving email, etc. I run the Injector as a Java application with arguments number-of-users, number-of-activities-per-day-per-user and number-of-days. The user names (first and last name) must be unique. To do so I have a list of 5000 first-names and a list of 5000 last-names, to make the user names unique I randomly select first-name and last-name from the lists, the unique users names I store in a Set and when I have the complete list I send it to the Injector that randomly creates activities for each user using Stream API .parallelStream().
My first performance test in for 500 users with 30 events per day per user and for 5 workdays = 75K documents. Creating the data for this test goes smooth, I create 500 unique user names into a Set collection and Threads go over the collection creating the activities for each user.
My challenge is in the second test (and I guess will continue to the next test) where I need data of 50K users: when the collection with user names is created I get OutOfMemoryException after about 10K users.
Is there a way to create the collection of user names that will keep the names unique and not cause an OutOfMemoryException?
I will appreciate any assistance, tip, and comment.

MongoDb multi document operation with a single document lock

For example< we have a next db structure:
Users
Items
Games
Items belongs to Users (userId field in item) aka inventory.
Users can create games.
Users can join created games. Only two users allowed to join a game.
When game is completed, all items from users inventories should be transferred to "winner" inventory.
I want to build a flow, by using NodeJs, to handle "joinGame", "winGame" cases.
In a MySql database i used transactions to lock "game" record and perform all operations in a single transaction to ensure data consistency.
I have no idea how to make it in mongo in a correct way.
Digging on internet, i found two solution:
Write a worker, what cycles through a "game" records to finalize them.
Use app-level (node executable) lock
?
Thank you in advance!

MongoDB : Search and modify a large number of documents on the basis of an array

I have a collection in mongoDB containing the information about registered users. Each document has an array containing the info about the friends of the given user.
user:{
_id:String,
phoneNo:String,
contacts:[{userid:ObjectId}]
.....
}
Now when a user registers from phone I get all the phone numbers from his contacts. I have to
search each of these phone numbers in the users collection and if they exist I have to push that number to the user.contacts array of both the registering user as well as the searched user.
Considering that the user collection to be quite big and I get around 100 phone numbers (which may or may not exist in the database) from each of the registering user.
What is the best way to achieve this?

Storing list in cassandra

I want to save a friends list in Cassandra where a user may have few hundred of friends . Should i store the list of friends, which is an email id, as a list or set in Cassandra or should i create a separate table having the columns user_id and friends which will include all the user(millions of users) along with their friends .
If i create a separate table with user_id and friends column will there be degradation in performance while retrieving the entire friend list of the user/ one friend of the user as the table will contain many records/rows.
It is important to note that lists and sets in Cassandra are not iterable. This means when you query for them, you get back the whole list or the whole set. If the collection has a high cardinality then this could pose issues in querying such as read timeouts or even a heap OOM error.
Since it sounds like there is no cap on the amount of friends one can have, one option could be to have a separate table that is partitioned on user and clustered on friend.
CREATE TABLE user_friends (
owner_user_id int,
friend_user_id int,
PRIMARY KEY(owner_user_id, friend_user_id)
);
This will ensure that the friend_user_id is in order and will allow you to do client side paging if the number of friends is very large. It also allows for a quick way to check if a person is a friend of a user.

Resources