Javatpoint Logo
Javatpoint Logo
CouchDB Interview Questions

CouchDB Interview Questions

1) What is CouchDB?

CouchDB is documented database server accessible through a RESTful JSON API. It is distributed, robust, incremental replication with bi-direction. It is schema-free with flat address space.

CouchDB is an open source NoSQL database which focuses on ease of use. It was developed by Apache. It is fully compatible with the web. CouchDB uses JSON to store data, JavaScript as its query language to transform the documents, using MapReduce, and HTTP for an API.

CouchDB features are as follows:

  • CouchDB can be replicated across multiple server instances.
  • CouchDB has various libraries for the language of your choice.
  • It has fast indexing and retrieval
  • It has a REST-like interface for document insertion, updates, recovery, and deletion.
  • CouchDB supports JSON-based document format, i.e., easily translatable across different languages.

Latest release: Version 2.2.0 on Aug 8, 2018


2) In which language CouchDB is written?

CouchDB is written in Erlang. It is a concurrent, functional programming language mainly focuses on fault tolerance (Erlang programming language also used for build massively scalable soft real-time system with requirements on high availability).

Some of its parts are written in C language too. As we know that CouchDB supports view server and the views (form map or reduce) are written in JavaScript per default (but can also be written in Erlang). Therefore CouchDB requires the JavaScript engine SpiderMonkey (which is written in C language).


3) In which language CouchDB's early work was started?

CouchDB early work was started in C++. But later, it was replaced by Erlang OTP platform.

Erlang has proven as an excellent match for this project.


4) How CouchDB is different from other SQL databases?

CouchDB is not a relational database. Some people think that it is a replacement for a relational database, but it is completely different from SQL databases. It is fast, efficient and faults tolerant.

Couch database SQL Databases
In CouchDB, JSON-based document format are used to store data, JavaScript for MapReduce indexes, and regular HTTP of its API.
Couch database is a database which stores data in the JSON document. Query your index and documents with the help of web browser via HTTP. All the indexes are combining with each other and transform with the help of JavaScript.
It is open source and uses RDBMS to store data. It is very fast, Multi-user, Multi-thread, and robust SQL (structured query language) database server.
SQL database generally used for big data storage of a large project.
It is a NoSQL database and likes manual transmission. It is a SQL database and likes automatic transmission.
Implemented in Erlang programming language Implemented in C, C++ programming languages.

Structure of NoSQL database:

CouchDB interview questions

5) Is CouchDB used in the Software industry?

CouchDB is very popular now a day, and many companies are using CouchDB.

These are the essential features of CouchDB:

  • CouchDB can be replicated across multiple server instances.
  • CouchDB has various libraries for the language of your choice.
  • It has fast indexing and retrieval
  • It has a REST-like interface for document insertion, updates, recovery, and deletion.
  • CouchDB supports JSON-based document format, i.e., easily translatable across different languages.

That's why the software companies use CouchDB.

Here we have a list of Top companies which uses CouchDB:

Company Website Revenue Company size Country
GrubHub Inc. grubhub.com 200M-1000M 1000-5000 United States
Hothead Games, Inc. hotheadgames.com 10M-15M 50-200 Canada
Ultimate software group Inc. Ultimatesoftware.com 200M-1000M 1000-5000 United States
SLALOM,LLC Slalom.com 200M-1000M 5000-10000 United States
GenCorp technologies Credera.com 10M-50M 200-500 United States

6) What is the difference between CouchDB and MongoDB?

These are the following differences:

Criteria CouchDB MongoDB
Interface REST/HTTP TCP/IP Custom Protocol
Object Storage Record is stored in documents in the database. Record is stored in collections in the database.
Replication It follows Master-Master replication. It follows Master-Slave replication.
Query Method CouchDB follows Map/Reduce query method. (JavaScript+others) MongoDB follows Map/Reduce (JavaScript) creating collection + object-based query language.
Data Model It follows the document-oriented model and data is presented in JSON format. Document-Oriented (BSON)
Concurrency MVVC (Multi-version concurrency control). Update-in-place
Preference CouchDB favors availability MongoDB favors Consistency
Performance consistency In CouchDB, data is safer than MongoDB In MongoDB, the database contains collections and collection contains documents.It is faster than CouchDB.
Written in It is written in Erlang. It is written in C++.

MongoDB is faster than CouchDB, and scalability is also better of the MongoDB.

CouchDB runs on different operating system like Android, iOS platform but MongoDB doesn't support mobile OS. Mongo DB is better as compare to CouchDB for rapid growth when the structure is not clearly defined from the beginning.


7) What is the similarity between MongoDB and CouchDB?

The similarity between MongoDB and CouchDB are:

  • MongoDB and CouchDB both are the document-oriented databases.
  • MongoDB and CouchDB both are the best examples of an open-source NoSQL database. i.e., both are Schema-free.
  • MongoDB and CouchDB both support JavaScript, can be used in queries, support aggregation functions such as MapReduce and sent the database to execute it.
  • MongoDB and CouchDB both support common programming languages C, C#, Erlang, Java, JavaScript, Ruby, Python, Haskell, PHP, Perl, Smalltalk, etc.

These are some common functionality of CouchDB and MongoDB.


8) What are the main features of CouchDB?

  • JSON Documents: CouchDB stores data in JSON document.
  • RESTful Interface: CouchDB does all tasks like replication, data insertion, etc. via HTTP.
  • N-Master Replication: CouchDB facilitates you to make use of an unlimited amount of 'masters,' making for some very interesting replication topologies.
  • Built for Offline: CouchDB can replicate to devices (like Android phones) that can go offline and handle data sync for you when the device is back online.
  • Replication Filters: CouchDB facilitates you to filter precisely the data you wish to replicate to different nodes.
  • ACID semantics: The CouchDB file layout follows all the features of ACID properties. Once the data is entered into the disc, it will not be overwritten. Document updates (add, edit, delete) follow Atomicity, i.e., they will be saved completely or not saved at all. The database will not have any partially saved or edited documents. Almost all of these update are serialized, and any number of clients can read a document without waiting and without being interrupted.
  • Document storage: CouchDB is a NoSQL database which follows document storage. Documents are the primary unit of data where each field is uniquely named and contains values of various data types such as text, number, Boolean, lists, etc. Documents don't have a set limit to text size or element count.
  • Eventually consistency: CouchDB guarantees to provide availability and partition tolerance.
  • Authentication and Session Support: CouchDB facilitates you to keep authentication open via a session cookie like a web application.
  • Security: CouchDB also provides database-level security. The permissions per database are separated into readers and admin. Readers can both read and write to the database.
  • Validation: You can validate the inserted data into the database by combining with authentication to ensure the creator of the document is the one who is logged in.
  • Map/Reduce List and Show: The main reason behind the popularity of MongoDB and CouchDB is map/reduce system.

9) Why Does CouchDB not use Mnesia?

There are many reasons behind CouchDB not using Mnesia:

  • It provides a storage limitation of 2 gigs per file.
  • It requires validation and fixup cycle after a crash or power failure, so even if the size limitation is lifted, the fixup time on large files is prohibitive.
  • Mnesia has some useful features, but features of Mnesia aren't really useful for CouchDB.
  • Mnesia is not a general-purpose, large-scale database. It works best as a configuration type database.
  • Mnesia works best as a configuration type database. It is necessary for the normal operations. The type where the data is not central to the function of the application, but necessary for normal operation of it.
  • Things that need to update, configure and often reconfigure like a network router, HTTP proxies, etc. whose configuration data is rarely huge.

10) How would you use transactions with CouchDB?

CouchDB uses an "Optimistic concurrency" model. In this model, if you send a document version along with your update, CouchDB rejects the change if the current document version doesn't match to your sent update.

So, you have to re-frame many normal transaction based scenarios for CouchDB. It's helpful to approach problems from a higher level, rather than attempting to mold Couch to a SQL based world.

If you have a document describing the item, and it includes a field for "Quantity available", you can handle concurrency issues:

First of all recover document, note down property that sent by CouchDB along with database, after that, Decrement the quantity field, if it's greater than zero. After that, send the updated document back using the _rev property. Check, If the _rev matches the currently stored number, be done else if there is a conflict when _rev is not matched then recover the newest document version.

For example:

I would like to take a ("master product") document that contains all the data information like name, picture description, price, etc.

Here we have to create to a field (product-key and, Claimed-by) by adding a new document inventory-ticket, if you are spelling a model of a hammer and have 20 items to sell, you might have documents with keys like hammer-1, hammer-2 to represent each one individually.

Now, I would like to create a view that gives a list of available hammer

This gives me list of available tickets with their product_key, I could grab a group of these when someone wants to buy hammer then iterate through the sending updates until I successfully claim one.

Reduce

This gives me a list of total unclaimed inventory_ticket items.

This example represents that transaction with CouchDB is possible that it substantially reduces conflicting updates, and cut down on the needs to respond to a conflict with the new updates. In this model, you won't have multiple users attempting to change data in primary product entry. When you have multiple users for a single ticket, then you have to identify those users who want to retake it by your view, ignore those, and you move to the next ticket and try again.


11) As CouchDB is written in Erlang and Erlang is known as slow to adopt Unicode. So, if it creates a problem for CouchDB?

CouchDB uses Erlang binary internally. So, data come to CouchDB is always UTF-8 encoded. There is no problem occurred.


12) What is the usage of CouchDB?

CouchDB facilitates developers to write a client-side application which interacts directly to the Couch without the need of server-side middle layer. It reduces the time of development and handling replication. Its database is stored locally so the application can run almost no latency. The main objective of CouchDB is to run on the internet applications and the connected devices through which we access the internet.

  • CouchDB has an HTTP-based REST API, which makes communication with the database very easy.
  • CouchDB has the simple structure of HTTP resources and methods (GET, PUT, and DELETE) that are easy to understand and use.
  • In CouchDB, data is stored in the flexible document-based structure so, there is no need to worry about the structure of the data.
  • CouchDB facilitates users with powerful data mapping, which allows querying, combining, and filtering the information.
  • CouchDB provides easy-to-use replication, using which you can copy, share, and synchronize the data between databases and machines.

13) What do you know about couchdbKit?

The couchdbKit provides a framework for your Python application to access and manage Python applications. It offers features to easily access and manage CouchDB by a client, allow to manage databases, Couch database server, doc management, and view access.

Objects mostly reflect python object for service. Server and data objects could be used for example.

Steps to install couchdbkit:

  • Couchdbkit requires python 2.x superior to 2.6
  • To install Couchdbkit using pip you must make sure that you have a recent version on distribute installed.

  • $ curl -0 http://python-distribute.org/distribute_setup.py
  • $ curl sudo python distribute_setup.py
  • $ easy_install pip

To install or upgrade to a latest released version of couchdbkit

$ pip install couchdbkit


14) Can Views update documents or databases?

No. Views are always read-only for databases and their documents.

Views are used for the following purpose:

  • It filters the document from the database to find relevant data for a particular process.
  • Extracting data from documents and present it in a specific order.
  • Building indexes to find the document by any value or structure that resides in them and use these indexes to represent the relationship between documents.
  • Finally, with views, you can make all sorts of calculations on the data in your documents

For example:

If documents represent your company's financial transactions, a view can answer the question of what the spending was in the last week, month, or year.


15) What platforms are supported in CouchDB?

Most POSIX systems are supported like GNU/Linux and OS X. Window is not officially supported but it should work.


16) What is the use of sequences? How do you do sequences?

Sequences are often used to ensure unique identifiers for each row in a database table. Sequences are hard to realize with replication. CouchDB generates unique ids from its own, and you can specify your own as well, so you don't need a sequence here. If you use a sequence for something else, you might find a way to express in CouchDB in another way.


17) How can you do replication?

Replication: Replication synchronizes two copies of the same database; these databases live on the same server or can be live on two different servers. If you change one copy of the database, replication will send the details to another copy.

For replication, first you have to send request of HTTP to CouchDB with a source, and a target database and CouchDB will send the changes from source to target.

Let's see, how replication looks like:

Here $source_database and $target_database can be the names of local database or full URIs of remote databases. Both databases need to be created before they can be replicated from or to.


18) Is it possible to communicate to CouchDB without going through HTTP/ API?

CouchDB's data model and internal API map the REST/HTTP model in a very simple way that any other API would inherit some features of HTTP. However, there is a plan to refractor CouchDB's internals to provide a documented Erlang API.