0% found this document useful (0 votes)
28 views62 pages

BDM Redis Mongodb

Uploaded by

soledad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views62 pages

BDM Redis Mongodb

Uploaded by

soledad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 62

IoT Big Data Management

Prof. Sergio Flesca, Ing. Ermelinda (Linda) Oro


Plan of the Course
• Introduction to Big data management
• Part 1: Big data storage High-level Interfaces

Support / Integration
• Distibuted file systems
• NoSQL data stores
Data Processing
• Part 2: Big data processing and
acquisition
• Hadoop and MapReduce Data Storage
• Spark
• Part 3: Data Stream Processing
• Apache Storm Resource Management
• Apache Spark Streaming
• Apache Kafka Streams

31/03/20 IoT Big Data Management 2


What is NoSQL and why it is needed?
• NoSQL database stands for “Not Only SQL” or “Not SQL”. Carlo Strozzi
introduced the NoSQL concept in 1998.
• NoSQL is basically a database used to manage huge sets of
unstructured data, wherein the data is not stored in tabular relations
like RDBMS.
• the data size has increased tremendously to the range of petabytes
• the majority of the data comes in a semi-structured or unstructured format
from social media, audio, video, texts, and emails.
• a lot of “NULLS” which are of course expensive
• “big data” is generated at a very high velocity

31/03/20 IoT Big Data Management 3


NoSQL Data Stores
The simplest NoSQL
databases. In this,
each element is
A key is paired
stored with a key to
with a complex
identify it. In some
data structure
Key-value databases,
called Document.
we can even save the
Example:
type of data saved
MongoDB
along, like in Redis.

Used to store large Used to store


data sets (store networked
columns of data data.
together).

31/03/20 IoT Big Data Management 4


CAP Theorem
Consistency: all clients see the same data at
the same time. Every read receives the most
recent write or an error

The systems continues to The system continues to


operate even in the presence operate even in case of
of node failure. Every request network failures. The system
receives a (non-error) response continues to operate despite
— without the guarantee that an arbitrary number of
it contains the most recent messages being dropped (or
write delayed) by the network
between nodes

31/03/20 IoT Big Data Management 5


Advantages of NoSQL Databases
• Dynamic Schemas
• You can simply add details to some "tuples" of your database
• Sharding
• Large databases are partitioned into small, faster and easily manageable databases.
NoSQL database automatically spread the data across servers, fetch the data in the
fastest time from the server which is free, while maintaining the integrity of data.
• Replication
• Auto data replication is also supported in NoSQL databases by default. Hence, if one
DB server goes down, data is recovered using its copy created on another server in
the same network.
• Integrated Caching
• Many NoSQL databases have support for Integrated Caching, wherein the frequently
demanded data is stored in a cache to make the queries faster.

31/03/20 IoT Big Data Management 6


Key-value Data Model

31/03/20 IoT Big Data Management 7


NoSQL Data Stores

31/03/20 IoT Big Data Management 8


Key-value Data Model
• A simple data model:
• data as a collection of <key,value> pairs
• Strongly aggregate-oriented
• Value: an aggregate instance
• A value is mapped to a unique key
• The aggregate is opaque to the database
• Values do not have a known structure
• Just a big blob of mostly meaningless bit
• Access to an aggregate:
• Lookup based on its key
• Richer data models can be implemented on top

31/03/20 IoT Big Data Management 9


REmote DIrectory Server
(Redis)
An (in-memory) key-value store

31/03/20 IoT Big Data Management 10


REmote DIrectory Server (Redis)
• Data Model
• Key: PrintableASCII
• Value (https://redis.io/topics/data-types):

• Primitives: Strings
• Containers (of strings):
• Hashes
• Lists
• Sets
• Sorted Sets

31/03/20 IoT Big Data Management 11


REmote DIrectory Server (Redis)
• Data Model
• Key: PrintableASCII
• Value (https://redis.io/topics/data-types):

• Primitives: Strings
• Containers (of strings):
• Hashes
• Lists
• Sets
• Sorted Sets

31/03/20 IoT Big Data Management 12


REmote DIrectory Server (Redis)
• Data Model
• Key: PrintableASCII
• Value (https://redis.io/topics/data-types):

• Primitives: Strings
• Containers (of strings):
• Hashes
• Lists:
• are linked lists
• they enable to push and pop values at both
sides or in an exact position
• Sets
• Sorted Sets

31/03/20 IoT Big Data Management 13


REmote DIrectory Server (Redis)
• Data Model
• Key: PrintableASCII
• Value (https://redis.io/topics/data-types):

• Primitives: Strings
• Containers (of strings):
• Hashes
• Lists
• Sets
• Sorted Sets

31/03/20 IoT Big Data Management 14


REmote DIrectory Server (Redis)
• Data Model
• Key: PrintableASCII
• Value (https://redis.io/topics/data-types):

• Primitives: Strings
• Containers (of strings):
• Hashes
• Lists
• Sets
• Sorted Sets: non repeating collections of strings.
• A score is associated to each value.
• Values of a set are ordered, from the smallest to the
greatest score.
• Scores may be repeated.
• The presence of a score enables to rank or to retrieve the
elements as well as changing their order during the
31/03/20
lifetime of the sorted set IoT Big Data Management 15
REmote DIrectory Server
(Redis) with Docker
An (in-memory) key-value store

31/03/20 IoT Big Data Management 16


Redis with Docker: Start
• Pull the image: a lightweight container with redis preconfigured
• docker pull sickp/alpine-redis

31/03/20 IoT Big Data Management 17


Redis with Docker: Start Configuration
Create a small network named redis_network with one redis server and one
client
• Start container server: we create an isolated network with a Redis server
• docker network create redis_network
• docker run --rm --network=redis_network --name=redis-server sickp/alpine-redis
• Start container client: in another shell we can create a Redis client,
connected to the same network
• docker run --rm --network=redis_network -it sickp/alpine-redis redis-cli -h redis-
server
• Use the command line interface on the client to connect to the redis server
• redis-cli -h redis-server [-p (port-number)]
• docker ps -a

31/03/20 IoT Big Data Management 18


Redis: Atomic Operations with Strings
https://redis.io/commands/
• Get the value of key
redis> GET key
• Set the string value of a key
redis> SET key value [EX expire-time-in-secs]
• Append a value to a key
redis> APPEND key value
• Determine if a key exists
redis> EXISTS key [key ...]
• Delete a key
redis> DEL key [key ...]
• Find all keys matching the given pattern
redis> KEYS pattern
• Set if key does not exist
redis> SETNX key value
• Get old value and set a new one
redis> GETSET key value
• Set a timeout after which the key will be deleted
redis> EXPIRE key seconds

31/03/20 IoT Big Data Management 19


Redis – Example (Key-Value: Strings)
• Basic operations to create and save users

31/03/20 IoT Big Data Management 20


Redis – Example (Key-Value: Strings)
• SETNX userId2 giovanni
• GET userId1
• SETNX userId1 giovanni
• SET userId1 mario
• GET userId1
• GET userId1
• GET userId2

• APPEND userId1 rossi


• DEL userId1
• GET userId1
• EXISTS userId1
• EXISTS userId1
• EXISTS userId2
• EXISTS userId2
• EXPIRE userId2 10
31/03/20
• EXISTS userId2
IoT Big Data Management 21
Redis: Atomic Operations with Hashes
https://redis.io/commands/
• Get the value of a hash field
redis> HGET key field
• Set the string value of a hash field
redis> HSET key field value
• Determine if a hash field exists
redis> HEXISTS key field

• Get all the fields in a hash


redis> HKEYS key
• Get all the values in a hash
redis> HVALS key

31/03/20 IoT Big Data Management 22


Redis – Example (Key-Value: Hashes)
• Use case: a recommendation system for an online music player.
Objective: Suggest the next song based on the history of played songs
per genre.

• We create a counter for each genre played by each user.


• for each user an hashmap that associates a counter to each genre played

31/03/20 IoT Big Data Management 23


Redis – Example (Key-Value: Hashes)
• HKEYS user1counter • HDEL user1counter classic
• HSET user1counter rock 1 • 1) "rock" • HEXISTS user1counter classic
• HGET user1counter rock • 2) "classic"
• HKEYS user1counter
• 3) "pop"
• 1) “rock”
• HEXISTS user1counter classic • HVALS user1counter • 2) “pop”
• HGET user1counter classic • 1) "4"
• 2) "1" • HVALS user1counter
• HSET user1counter classic 1 • 3) "1" • 1) “4”
• 2) “1”
• HSET user1counter rock 4
• HGET user1counter rock

• HSET user1counter pop 1


• HEXISTS user1counter classic

31/03/20 IoT Big Data Management 24


Redis: Atomic Operations with Sets
https://redis.io/commands/
• Add one or more members to a set
SADD key member [member ...]
• Remove one or more members from a set
SREM key member [member ...]
• Get the number of members in a set
SCARD key
• Remove and return one or multiple random members from a set
SPOP key [count]

• Add multiple sets


SUNION key [key ...]
• Subtract multiple sets
SDIFF key [key ...]
• Intersect multiple sets
SINTER key [key ...]

31/03/20 IoT Big Data Management 25


Redis – Example (Key-Value: Sets)
• Use case: Retrieve bands or singers that play a specific musical genre.
• selecting bands belonging to multiple genres
• selection of bands that play the same kind of music

• We need to store bands/singers per each musical genre.


• We assume that a band can play several genres.

31/03/20 IoT Big Data Management 26


Redis – Example (Key-Value: Sets)
• SADD rock "pink floyd" • SDIFF rock pop
• SADD rock "queen" • 1) “pink floyd”
• SADD rock "nirvana" • 2) “queen”
• SADD jazz "paolo conte" • 3) “nirvana”
• SADD pop "paolo conte" • SUNION rock jazz
• 1) “pink floyd”
• SCARD rock • 2) “queen”
• SCARD Rock • 3) “nirvana”
• 4) “paolo conte”
• SADD pop "mozart" • SINTER rock pop
• SREM pop "mozart"

31/03/20 IoT Big Data Management 27


Redis: Atomic Operations with Sorted Sets
https://redis.io/commands/
• Add one or more values to a sorted set, or update its score if it already exists
ZADD key score value [score value ...]
• Remove one or more values from a sorted set stored at key
ZREM key value [value ...]
• Get the number of values in a sorted set stored at key
ZCARD key
• Get the score associated with the given value in a sorted set stored at key
ZSCORE key value

• Returns the index of a value in a sorted set


ZRANK key value
• Return a range of values in a sorted set, by index
ZRANGE key start stop [WITHSCORES]
• Return a range of values in a sorted set, by score
ZRANGEBYSCORE key min max [WITHSCORES] [LIMIT offset count]
• Increment the score of a value in a sorted set
ZINCRBY key increment member

31/03/20 IoT Big Data Management 28


Redis – Example (Key-Value: Sorted Sets)
• Use case: a recommendation system for an online music player.
Objective: Suggest the top-K genres that have been suggested and
listened by the user. We need to identify the number of reproduction
of the suggested genre

• We use sorted sets to store the number of reproduction of songs per


genre
• This data structure enable to automatically determines the top-K elements

31/03/20 IoT Big Data Management 29


Redis – Example (Key-Value: Sorted Sets)
• ZRANK urepr pop • ZRANGE urepr 0 1
• ZCARD urepr • 1) “jazz”
• ZRANK urepr rock • 2) “pop”
• ZADD urepr 1 rock
• ZRANGE urepr 0 -1
• ZADD urepr 1 jazz • ZINCRBY urepr 3 rock • 1) “jazz”
• ZADD urepr 1 pop • ZINCRBY urepr 1 pop • 2) “pop”
• 3) “rock”
• ZCARD urepr • ZRANGE urepr 0 -2
• ZREM urepr pop • ZRANK urepr pop • 1) “jazz”
• ZRANK urepr rock • 2) “pop”
• ZCARD urepr
• ZRANGEBYSCORE urepr 3 10
• ZSCORE urepr jazz • 1) "rock"

31/03/20 IoT Big Data Management 30


Redis: Atomic Operations with Lists
https://redis.io/commands/
• Push value at the head|tail of the list in key
redis> LPUSH|RPUSH key value [value]
• Remove and return the head|tail of the list in key
redis> LPOP|RPOP key
• Get the length of the list
redis> LLEN key
• Get a range indicated with indexes of elements from a list
redis> LRANGE key start stop
• Remove elements from a list
LREM key count element

31/03/20 IoT Big Data Management 31


Redis – Example (Key-Value: Lists)
• Use case: a recommendation system for an online music player.
• The music player store the playlist for the user
• Playlist of the user can be populated by the user or by the recommendation
system.

31/03/20 IoT Big Data Management 32


Redis – Example (Key-Value: Lists)
• RPUSH uplay "time" • LPOP uplay
• RPUSH uplay "money" • LLEN uplay
• LPUSH uplay "glory days" • LREM uplay 0 "glory days"
• LRANGE uplay 0 -1
• LLEN uplay • 2) “time”
• 3
• 3) “money”
• LRANGE uplay 0 -1
• 1) “glory days” • # overrides data or out of range:
• 2) “time”
• 3) “money” • LSET uplay 1 "we will rock you"
• LRANGE uplay 0 -1
• LRANGE uplay -2 -1 • 1) "time"
• 1) “time” • 2) "we will rock you"
• 2) “money”

31/03/20 IoT Big Data Management 33


Redis with Docker: End
Stop and Remove the created Docker environment
(new cmd window)
• Stop and delete the namenode and datanodes
• docker kill redis-server
• docker ps -a -q
• ba8ea1d2b258
• docker kill ID
• docker kill ba8ea1d2b258
• Remove the network
• docker network remove redis_network

31/03/20 IoT Big Data Management 34


Plan of the Course
• Introduction to Big data management
• Part 1: Big data storage High-level Interfaces

Support / Integration
• Distibuted file systems
• NoSQL data stores
Data Processing
• Part 2: Big data processing and
acquisition
• Hadoop and MapReduce Data Storage
• Spark
• Part 3: Data Stream Processing
• Apache Storm Resource Management
• Apache Spark Streaming
• Apache Kafka Streams

31/03/20 IoT Big Data Management 35


Document Data Model

31/03/20 IoT Big Data Management 36


NoSQL Data Stores

31/03/20 IoT Big Data Management 37


Document Data Model
• A simple data model:
• data as a collection of <key, document> pairs
• A document:
• is an aggregate instance
• can contain complex data structures (nested objects)
• does not require adherence to a fixed schema
• Access to the aggregate (document):
• Structure of the aggregate visible
• Often there are limitations on its content type
• Queries based on the fields in the aggregate

31/03/20 IoT Big Data Management 38


MongoDB
A Document Data Store

31/03/20 IoT Big Data Management 39


MongoDB
• documents are grouped together into collections
• Each document of a collection should have a unique key in the
collection
• Documents can have different schema.

RDMS (e.g. MySQL) MongoDB


Tables Collections
Records/ Rows Documents
Query returns records Queries return a cursor

31/03/20 IoT Big Data Management 40


MongoDB
• MongoDB represents JSON documents using BSON
• a binary-encoded format that extends the JSON model to provide additional data
types
Data Types
• String: combination of characters
• Boolean: True or False
• Integer: digits
• Double: a type of floating point number
• Null: not zero, not empty _id: ObjectId("5bd2f98397791"),
• Array: a list of values
• Object: an entity which can be used in
programming (value, variable, function, or data
structure).
• Timestamp: a 64 bit value referring to a time
• Internationalized Strings: UTF-8 for strings fields: value
• Object IDs: every document must have an
Object ID which is unique
31/03/20 IoT Big Data Management 41
MongoDB – dot notation

• To access the elements of an array


• array_name.zero_based_index_position
• Eg. "contribs.2" to specify the 3° element
{ ...
contribs: [ "Turing machine", "Turing test", ... ],
... }

• To access the fields of an embedded document


• embedded_document_name.field_name
• E.g. specify the last name: "name.last
{ ...
name: { first: "Alan", last: "Turing" },
... }

31/03/20 IoT Big Data Management 42


MongoDB – sharded cluster
• Sharding: A database architecture that partitions data by key ranges
and distributes the data among two or more database instances.
Sharding enables horizontal scaling.

• A MongoDB sharded cluster consists of the following components:


• shard: Each shard contains a subset of the sharded data. Each shard can be
deployed as a replica set.
• mongos: The mongos acts as a query router, providing an interface between
client applications and the sharded cluster.
• config servers: Config servers store metadata and configuration settings for
the cluster. Config servers must be deployed as a replica set (CSRS).

31/03/20 IoT Big Data Management 43


MongoDB – sharded cluster

31/03/20 IoT Big Data Management 44


MongoDB with Docker
A Document Data Store

31/03/20 IoT Big Data Management 45


MongoDB with Docker: Start
• Pull the image with pre-installed MongoDB: the official container
• docker pull mongo

31/03/20 IoT Big Data Management 46


MongoDB with Docker: Start Configuration
Create an isolated network with a MongoDB server
• docker network create mongonet
• docker run -i -t -p 27017:27017 --name mongo_server --network=mongonet
mongo:latest /usr/bin/mongod --bind_ip_all
• In another shell we can create a Mongo client, connected to the same
network
• docker run -i -t --name mongo_cli --network=mongonet mongo:latest /bin/bash
• On the client, we open the command line interface "mongo", specifying the
address of the server
• mongo mongo_server:27017
• docker ps -a
31/03/20 IoT Big Data Management 47
MongoDB - Example
• Use case: a content management system that manage posts, images,
videos, and so on, each with its own specific attributes

• Examples of objects to manages


• { name : "hello world", type : "post", size : 250, comments : ["c1", "c2"] }
• { name : "sunny day", type : "image", size : 3, url : "abc" }
• { name : "tutorial", type : "video", length : 125, path : "/video.flv", metadata :
{quality : "480p", color: "b/n", private : false } }

31/03/20 IoT Big Data Management 48


MongoDB - Example
• Create and switch to a new database, for instance named "cms"
• use cms

• Insert a document: insert a document into a collection. The operation


will create the collection if it does not exist yet.
• Insert in a collection named "cms" several documents (a post, an image, and a
video)
• db.cms.insert({ name : "hello world", type : "post", size : 250, comments : ["c1", "c2"] } )
• db.cms.insert({ name : "sunny day", type : "image", size : 300, url : "abc" })
• db.cms.insert({ name : "tutorial", type : "video", length : 125, path : "/video.flv",
metadata : {quality : "480p", color : "b/n", private : false } })

31/03/20 IoT Big Data Management 49


MongoDB Cli - Query
• Querying the database to find documents: the find() method issues a
query to retrieve data from a collection. All queries have the scope of
a single collection.
• Queries can return all documents or only those matching a specific filter or
criteria
• The find() method returns results in a cursor (an iterable object that yields
documents)

31/03/20 IoT Big Data Management 50


MongoDB Cli - Query
• Exact match
• db.mycoll.find({"price" : 300 })
• Comparison (eq, gt, gte, lt, lte, in, nin):
• db.mycoll.find({"price" : { $gt: 300 } })
• db.mycoll.find({"year" : { $in: [2012, 2016] } })
• Existence (if document contains a field):
• db.mycoll.find({"discount" : { $exists: true } })
• logical (and, or, not, nor):
• # AND:
• db.mycoll.find({field1 : {...}, field2 : {...} })
• # OR:
• db.mycoll.find({$or: [{...}, {...}]})
• Sort query results: to specify an order for the result set, append the sort() method to the query.
Pass to sort() a document which contains the field(s) to sort by and the corresponding sort type (1
for ascending, -1 for descending)
• db.mycoll.find().sort( { "name" : 1 } )
31/03/20 IoT Big Data Management 51
MongoDB - Example
• db.cms.find()
• { "_id" : ObjectId("..."), "name" : "hello world", "type" : "post", "size" : 250,
• "comments" : [ "c1", "c2" ] } { "_id" : ObjectId("…"), "name" :"sunny day", "type" :
"image", "size" : 300, "url" : "abc" }
• { "_id" : ObjectId("..."), "name" :"tutorial", "type" : "video", "length" : 125, "path"
:"/video.flv", "metadata" : { "quality" : "480p", "color" :"b/n", "private" : false } }

31/03/20 IoT Big Data Management 52


MongoDB - Example
• db.cms.find({type : "image" } )
• db.cms.insert({ name : "mycms-logo", type : "image", size : 3, url :
"cms-logo.jpg" })
• db.cms.find({type : "image" } )

• db.cms.find( {size : { $gt : 100 } } )


• db.cms.find( {size : { $lt : 100 } } )

31/03/20 IoT Big Data Management 53


MongoDB - Example
• db.cms.find({ length : { $exists: true } } )
• db.cms.find({ comments : { $exists: true } } )
• db.cms.find({ "comments.2" : { $exists: true } } )
• db.cms.find({ "comments.1" : { $exists: true } } )

• db.cms.find({ "metadata.quality" : { $exists: true } } )


• db.cms.find({ "metadata.quality" : "360p" } )
• db.cms.find({ "metadata.quality" : "480p" } )
• db.cms.find({ "metadata.private" : false } )

• db.cms.findOne({ comments : { $exists: true } } )


• db.cms.findOne({ comments : { $exists: true } } ).comments[1]

31/03/20 IoT Big Data Management 54


MongoDB - Example
• A slightly more complex query, that combines multiple conditions in a
logical AND or OR condition:
• db.cms.find( {size : { $gt : 100 } , type : "image" } )
• db.cms.find( { $or : [ { size : { $gt : 100 } } , { type : "image" } ] } )
• Sort results in ascending (value = 1) or descending order (value = -1)
• db.cms.find().sort( { name : 1 } )
• db.cms.find({type : "image" }).sort( { name : -1 } )
• Sorting with Non-existent Fields
• The comparison treats a non-existent field as if it were an empty BSON Object. As
such, a sort on the a field in documents { } and { a: null } would treat the
documents as equivalent in sort order.
• Return to the initial sort (how documents were inserted in the collection)
• db.cms.find().sort( { nonexistingfield
31/03/20
:1})
IoT Big Data Management 55
MongoDB Cli - Basic operations
• Update a document: using update()
• there are several way to update a document. For example, we can simply
update a subset of fields using the operator $set
• The update can be applied to one or multiple occurrencies that matches the update
filter.
db.mycoll.update(
{ field : value },
{ $set: { "address.street": "East 31st Street" }
})

db.mycoll.update(
{ field : value },
{ $set: { ... } },
{multi: true} )

31/03/20 IoT Big Data Management 56


MongoDB - Example
• Update a document: the previous command changes only the first
occurrence;
• db.cms.update({ "name" : "Canon EOS 750D" }, { $set: { "address.street": "East 31st
Street" } } )

• Update performed on multiple occurrences: the parameter "multi" is used


• db.cms.update({ "name" : "mycms-logo" }, { $set: { "metadata.quality": "hd" } } )

• db.cms.find({name : "mycms-logo"})
• db.cms.find({type : "image"})
• db.cms.update({ type : "image" }, { $set: { "metadata.author": "myname" } } , {multi:
true} )
• db.cms.find({type : "image"})

31/03/20 IoT Big Data Management 57


MongoDB - Example
• Update a document: how to add a new element to an array (using the
operator $push):
• db.cms.find({ type : "post" } )
• db.cms.update({ name : "hello world" }, { $push: { "comments": "a new comment" }
})
• db.cms.update({ name : "hello world" }, { $push: { "comments": "a second new
comment" } } )
• db.cms.find({ type : "post" } )

• # Update a document: override the whole document


• db.cms.find()
• db.cms.update({ name : "mycms-logo" }, { author : "myname" } )
• db.cms.find()

31/03/20 IoT Big Data Management 58


MongoDB Cli - Basic operations
• Remove documents.
• By default .remove() removes all the documents that match the document
fields passed as argument.
• If a single delete should be performed, we need to use the parameter
"justOne".

• db.cms.remove( { type : "video" } )


• db.cms.find()
• db.cms.remove( { author : "myname" } , { justOne: true } )
• db.cms.find()
• Removes all documents
• db.cms.remove( { } )

31/03/20 IoT Big Data Management 59


MongoDB Cli - Basic operations
• We can also drop the whole collection (together with its documents)

• db.cms.drop()

31/03/20 IoT Big Data Management 60


MongoDB with Docker: End
Stop and Remove the created Docker environment
(in another cmd window)
• Stop and delete the namenode and datanodes
• docker kill mongo_server mongo_cli

• docker rm mongo_server
• docker rm mongo_cli
• docker ps -a

• Remove the network


• docker network remove mongonet
31/03/20 IoT Big Data Management 61
Find a right trade-off
• A cache is a component that stores recently accessed data in a faster
storage system
• Use case: the management of a library

https://www.sitepoint.com/caching-a-mongodb-
database-with-redis/
Use an in-memory key-value store as caching system!
31/03/20 IoT Big Data Management 62

You might also like