Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] Database replication #264

Closed
shd101wyy opened this issue Dec 4, 2017 · 5 comments
Closed

[Question] Database replication #264

shd101wyy opened this issue Dec 4, 2017 · 5 comments
Labels

Comments

@shd101wyy
Copy link

shd101wyy commented Dec 4, 2017

Hi there,

I am now developing a twitter like web application using orbit-db.
Assume I have a userA who starts a nodeA. He stored all his tweets in a feed type database called tweetsDB. userA posts 1000 tweets in total stored in database tweetsDB.
Now another useruserB on nodeB wants to see the most recent 5 tweets of userA.
So userB would try to connect to tweetsDB.
Does that mean userB has to download (replicate) the whole tweetsDB including those 1000 tweets in order to see the most recent 5 tweets?

Thank you

@haadcode
Copy link
Member

haadcode commented Dec 6, 2017

In short: no, they don't need to replicate 1000 tweets to display 5 :)

You can do this by giving the load() function a number of entries to load, eg. await db.load(5). OrbitDB will then load the database with 5 latest operations (tweets) and emit ready event and finish loading. After that, it'll load the rest of the 1000 tweets in the background.

Does that help?

@haadcode
Copy link
Member

haadcode commented Dec 6, 2017

And in case where userB doesn't have any of userA tweets, you don't need to do anything special but to open the database and userB will start replicating userA tweets automatically. You can listen for the replicated event to learn when the database has updated.

@shd101wyy
Copy link
Author

Hi @haadcode ,

Thank you much for your reply. It's extremely helpful.
I have a few other questions here. I just want to make sure that I understand everything correctly before I continue my project with the fancy orbit-db library ;)

  1. You said that I could use await db.load(5) to load the database with 5 latest operations (tweets) locally or listen to replicated event for the data update happened remotely. Is there a way to load the 5 oldest operations first instead of the 5 most recent operations?

  2. When database is replicated from another remote database, does it replicate everything randomly or is there an order of replication like starting from the latest to the oldest?

  3. When two users try to update an entry in database at the same time, what would happen? For example, two users click the like button in a tweet at the same time.

  4. For the document store type database, how fast is it to query an entry by its _id. I would assume that in the worst case it would be O(n) because the data is stored in a linked list?

  5. Is there a way to stop replicating the database and then resume from where I stopped?

  6. If I use orbit-db in browser, how will the database be stored? IndexedDB?

Thank you very much for your patience.

@aphelionz
Copy link
Member

@shd101wyy I know this is very, very late but I still think answering your question will be helpful to others as well.

You said that I could use await db.load(5) to load the database with 5 latest operations (tweets) locally or listen to replicated event for the data update happened remotely. Is there a way to load the 5 oldest operations first instead of the 5 most recent operations?

Yes, certain data stores have an iterator function that can probably help you.

When database is replicated from another remote database, does it replicate everything randomly or is there an order of replication like starting from the latest to the oldest?

Replication will start from the exchanged "heads" i.e. the latest entry or entries in the DAG, and replicate from there by following the next field inside of the entries.

When two users try to update an entry in database at the same time, what would happen? For example, two users click the like button in a tweet at the same time.

OrbitDB implements the ipfs-log, which in turn uses something called Lamport Clocks to ensure that even if they press the button a the exact same microsecond, they will be properly sorted.

For the document store type database, how fast is it to query an entry by its _id. I would assume that in the worst case it would be O(n) because the data is stored in a linked list?

That sounds right.

Is there a way to stop replicating the database and then resume from where I stopped?

I don't believe so, no...

If I use orbit-db in browser, how will the database be stored? IndexedDB?

Yes, it's stored in IndexedDB via a library called LevelDB.


Finally, we also just released the OrbitDB Field Manual and I encourage everybody to check it out and open new issues / PRs there if you see fit.

@shd101wyy
Copy link
Author

@aphelionz Thank you very much for your replies!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants