Reactive Architecture: CQRS & Event Sourcing Quiz Answers

Get Reactive Architecture: CQRS & Event Sourcing Quiz Answers

Command Query Responsibility Segregation (CQRS), and Event Sourcing (ES), are powerful tools. They can make the difference between an application that evolves, and remains competitive, or one that stagnates and falls into obscurity.

This course will discuss the reasons we use CQRS/ES, what benefits it provides us, but also what it will cost us to use. We will see how CQRS/ES can impact the scalability, consistency, and availability of our application. Most importantly we will learn about one of the key techniques that is used in building modern Reactive Microservices.

Enroll on Cognitive Class

What is CQRS/ES Review

Question: CQRS stands for:

  • Control Query Responsibility Segregation
  • Command Query Read Separation
  • Control Query Read Segregation
  • Command Query Responsibility Segregation

ES stands for:

  • Entity Segregation
  • Event Sourcing
  • Entity Sourcing
  • Event Separation

Question: True or False: You must always use CQRS and Event Sourcing together. They can’t be used independently.

  • True
  • False

Question: You should consider using CQRS/ES if:

Note: Make sure you select all of the correct options—there may be more than one!

  • It will give you a competitive advantage.
  • You need auditability.
  • You can replace that portion of the system with an off the shelf product.
  • Your system experiences relatively low traffic.
  • You need additional resilience or scalability.

State Based Persistence Review

Question: State Based Persistence means:

  • The events that led up to the current state are persisted, rather than the state itself.
  • Each update adds a new state to the previous one, retaining both.
  • Each update replaces the previous state with a new state.
  • Data is geographically ordered according to what state the data was created in.

Question: True or False: Domain requirements are fluid, rather than fixed. They can change over time depending on many factors.

  • True
  • False

Question: When using State Based Persistence, if a change needs to be made to the domain we can usually apply that change:

  • To all entries in the system, both new and old.
  • Only to old entries in the system.
  • To any new entries into the system.
  • Nowhere. State Based Persistence presents us from changing the domain.

Question: If the persisted state in our system is incorrect due to an error in our code, we can usually:

  • Fix the code, and the incorrect state.
  • Fix the incorrect state, but not the code.
  • Fix the code, but not the incorrect state.
  • Fix nothing.

Question: True or False: State Based Persistence captures the journey, rather than the destination.

  • True
  • False

Event Sourcing Review

Question: When using State Based Persistence, in order to recover from errors in state, or evolve our domain we can:

  • Use shadow copies of the database to build a full history of the state.
  • Leverage backup copies of our data, and restore them as necessary.
  • Run scripts to retroactively modify existing records in the database.
  • Persist an audit log alongside our state so we understand where the state came from.

Question: When an audit log is stored alongside the state, we must be wary of which of the following:

  • If the audit log and the state disagree, we have two potential sources of truth.
  • The audit log and the state must be updated in a transactional way.
  • A bug in the code may cause the state and the audit log to become out of sync.
  • All of the above
  • None of the above

Question: Which of the following is true for Event Sourcing:

Note: Make sure you select all of the correct options—there may be more than one!

  • Persists both state and intent.
  • The Event Log can be reconstructed from the persisted state.
  • Captures intent.
  • Eliminates the persistence of state.
  • Uses only the audit log.

Question: In an Event Sourced system, state is recovered by:

  • Keeping the state in a separate table(s) in the database.
  • Using the state defined in the newest event.
  • Using the state defined in the oldest event.
  • Replaying events and performing the same state updates as when the event originally occured.

Question: True or False: If you replay events in an Event Sourced system, you must also replay the side effects.

  • True
  • False

Question: A snapshot should be created:

  • When we need to delete old events in order to free up space.
  • After every event.
  • When the time to restore from the log is becoming excessive.
  • All of the above.
  • None of the above.

Question: Benefits of Event Sourcing include:

Note: Make sure you select all of the correct options—there may be more than one!

  • A simpler model for complex database queries.
  • The ability to correct errors in state by replaying events.
  • The ability to rewind state to fix or diagnose issues.
  • Auditability in cases where that is critical (eg. Legal requirements)
  • A data model that maps naturally to relational databases.

Question: In the Lightbend Ecosystem you can find Event Sourcing in:

  • Akka Persistence
  • Akka Cluster Sharding
  • Akka Distributed Data
  • Lagom Persistent Entities
  • Lagom Message Brokers

Evolving the Model Review

Question: Which of the following statements is FALSE:

  • The integrity of the log is critical to the success of the system.
  • The log in an Event Sourced system should be append only.
  • Events represent future changes to the system.
  • All of the above.
  • None of the above.

Question: If you need to evolve your data model, you should do so by:

  • You can not evolve your data model.
  • Running a script to edit the existing events.
  • Creating a snapshot and deleting the old events.
  • Creating a new version of the event.

Question: True or False: Java Serialization is an excellent choice for serializing your events.

  • True
  • False

Question: Versioning of Events can be handled in the Lightbend ecosystem using:

  • Lagom Persistent Entities
  • Akka Serialization
  • Akka Persistence Query
  • Akka Event Adapters

Command Sourcing Review

Question: When using Command Sourcing, the order we do things is:

  • Persist the Event, Execute the Command
  • Execute the Command, Persist the Command
  • Execute the Command, Persist the Event
  • Persist the Command, Execute the Command

Question: Which of the following are potential challenges with Command Sourcing:

Note: Make sure you select all of the correct options—there may be more than one!

  • Commands must be idempotent.
  • Commands may get lost.
  • If a Command is invalid, we are unable to inform the user.
  • Invalid Commands can block the queue.
  • Invalid Commands may corrupt the state of the system.

Question: True or False: Akka Persistence can be used to implement Command Sourcing.

  • True
  • False

Case Study: Reactive BBQ Events

Question: Using this existing table structure, can we determine how often an order is cancelled either before, or after it has been placed?

  • Yes
  • No

Question: Which of the following events would the Reactive BBQ Order system need to track in order to determine how often an order is cancelled either before, or after it has been placed?

Note: Make sure you select all of the correct options—there may be more than one!

  • OrderCreated(locationId, serverId, tableId)
  • ItemAddedToOrder(orderId, itemId, quantity)
  • OrderPlaced(orderId)
  • OrderClosed(orderId)
  • OrderCancelled(orderId)

Question: Which of the following problems might they encounter while trying to determine if people are ordering drinks after tasting their Reactive Wings or ReactiveRibs?

Note: Make sure you select all of the correct options—there may be more than one!

  • There is no way to tell when an item was served.
  • There is no way to tell when an order was placed.
  • There is no way to determine the order that items were added to the menu.
  • There is no way to tell what kind of item was added (Was it a glass of milk? Or was it an order of fries?)
  • There is no way to tell how many guests are at the table.

Question: If we simply added timestamps to the Order Items Table, would that solve our problem?

  • Yes
  • No

Question: What events would we need to track in order to determine if a drink is being added after our wings or ribs are served?

Note: Make sure you select all of the correct options—there may be more than one!

  • ItemAddedToOrder(orderId, itemId, quantity)
  • OrderPlaced(orderId)
  • ItemPrepared(orderId, itemId)
  • ItemServed(orderId, itemId)
  • ItemTasted(orderId, itemId)

Read Models Vs Write Models Review

Question: Which of the following is a potential problem in an Event Sourced system:

  • Commands that span multiple aggregate roots become difficult.
  • Queries that access a single aggregate root become difficult.
  • Commands that are executed by a single aggregate root become difficult.
  • Queries that span multiple aggregate roots become difficult.

Question: True or False: The problem of conflicting models in our system is unique to Event Sourced systems.

  • True
  • False

Question: Fundamentally, the problem that we have encountered with these conflicting models is:

  • Our writes (Commands) and reads (Queries) shouldn’t live in the same microservice.
  • In a system of sufficient size, the idea of using a domain model rapidly breaks down.
  • Models that are focused around aggregate roots ignore the possibility of transactions that cross aggregate root boundaries.
  • A model that is optimized for writes (Commands) may not be optimized for reads (Queries).

CQRS Review

Question: True or False: The requirements for read and write in our system should be more or less the same.

  • True
  • False

Question: Most applications tend to have:

  • Balanced reads and writes.
  • More writes than reads.
  • More reads than writes.
  • Read, or read not. There is no write.

Question: In a CQRS based system, the Commands are handled by the:

  • Read Model
  • Write Model

Queries are handled by the:

  • Read Model
  • Write Model

Question: True or False: Event Sourcing is critical for CQRS systems. You can’t use CQRS without Event Sourcing.

  • True
  • False

Question: When building a system with both CQRS and Event Sourcing, the components we normally include are:

Note: Make sure you select all of the correct options—there may be more than one!

  • Read Model
  • Write Model
  • Event Store
  • Event Bus/Message Bus (eg. Kafka, RabbitMQ etc)
  • Denormalized Store

Question: True or False: An ideal read model is often setup so the data can be read directly from a single table in the database, as is, with minimal additional processing/formatting.

  • True
  • False

Question: Polyglot Persistence means:

  • Creating transactions that span multiple databases.
  • Storing data in large blobs, rather than in a columnar format.
  • Separating your reads and writes in the database.
  • Using different databases within your system, depending on the use case.

Question: Which of the following is a disadvantage of using CQRS:

  • Optimization of the read model is restricted by the needs of the write model.
  • Optimization of the write model is restricted by the needs of the read model.
  • The initial choice of database will impact all areas of the system (both reads and writes).
  • All of the above.
  • None of the above.

Question: A key benefit to combining CQRS and Event Sourcing is:

  • The presence of the event log allows all new projections to be retroactive.
  • The read and write models are decoupled, allowing them to evolve independently.
  • The read and write models can be optimized individually, depending on their needs.
  • All of the above.
  • None of the above.

Question: In the Lightbend Ecosystem, CQRS can be implemented using:

Note: Make sure you select all of the correct options—there may be more than one!

  • Akka Cluster Sharding
  • Akka Distributed Data
  • Lagom Read Side Processors
  • Akka Persistence Query
  • Lagom Message Brokers

Case Study: Reactive BBQ Read Models

Question: Assuming we had access to the above events, what table structure could we use to answer the question “how often are orders cancelled after they are placed”?

Note: Make sure you select all of the correct options—there may be more than one!

  • Table: Orders – Columns: orderId, locationId, serverId, tableId, status (one row per order)
  • Table: OrdersStatuses – Columns: orderId, status, timestamp (one row per change in status)
  • Table: OrderStatusTransitions – Columns: orderId, oldStatus, newStatus, timestamp (one row per change in status)
  • Table: CancelledOrders – Columns: orderId, timestamp (one row per orderId)
  • Table: OrdersCancelledAfterPlaced – Columns: orderId, timestamp (one row per orderId)

Question: Which of these table structures would provide the most efficient query?

  • Table: Orders – Columns: orderId, locationId, serverId, tableId, status (one row per order)
  • Table: OrdersStatuses – Columns: orderId, status, timestamp (one row per change in status)
  • Table: OrderStatusTransitions – Columns: orderId, oldStatus, newStatus, timestamp (one row per change in status)
  • Table: CancelledOrders – Columns: orderId, timestamp (one row per orderId)
  • Table: OrdersCancelledAfterPlaced – Columns: orderId, timestamp (one row per orderId)

Question: Assuming we had access to the above events, what table structure could we use to answer the question “how often do customers order milk after being served Reactive Wings or Ribs”?

Note: Make sure you select all of the correct options—there may be more than one!

  • Table: OrderItems – Columns: orderId, itemId, quantity (one row per orderId)
  • Table: OrdersWithMilk – Columns: orderId, timestamp (one row per orderId)
  • Table: MilkOrderedAfterRibsServed – Columns: orderId, timestamp (one row per orderId)
  • Table: MilkOrderedAfterWingsOrRibsServed – Columns: orderId, timestamp (one row per orderId)
  • Table: DrinkOrderedAfterWingsOrRibsServed – Columns: orderId, drinkId, timestamp (one row per drink per order)

Question: Which of these table structures would provide the most efficient query?

  • Table: OrderItems – Columns: orderId, itemId, quantity (one row per orderId)
  • Table: OrdersWithMilk – Columns: orderId, timestamp (one row per orderId)
  • Table: MilkOrderedAfterRibsServed – Columns: orderId, timestamp (one row per orderId)
  • Table: MilkOrderedAfterWingsOrRibsServed – Columns: orderId, timestamp (one row per orderId)
  • Table: DrinkOrderedAfterWingsOrRibsServed – Columns: orderId, drinkId, timestamp (one row per drink per order)

Fine Grained Microservices Review

Question: True or False: In a CQRS/ES based system, the read and write models should always live in the same microservice.

  • True
  • False

Question: True or False: Microservices are cheap and easy. We shouldn’t have to worry about adding new ones.

  • True
  • False

Consistency, Availability & Scalability with CQRS Review

Question: Simple CQRS (without event sourcing) promises what kind of consistency?

  • Weak Consistency
  • Eventual Consistency
  • Strong Consistency
  • Whatever consistency is provided by your underlying database

Question: CQRS with Event Sourcing promises what kind of consistency?

  • Whatever consistency is provided by your underlying database
  • Strong Consistency
  • Eventual Consistency
  • Different consistency options for both your read, and write models.

Question: Strong Consistency is most important for:

  • Read Models
  • Write Models
  • Both
  • Neither

Question: Pure reads are:

  • Sometimes eventually consistent.
  • Always strongly consistent.
  • Never eventually consistent.
  • Always eventually consistent.

Question: Which of the following options could be used to scale a read model?

  • Caching
  • Separate microservices for individual read models
  • Duplicating read models in the same, or different databases
  • All of the above
  • None of the above

Question: True or False: The write side of CQRS systems require Strong Consistency, and therefore are inherently not scalable.

  • True
  • False

Question: True or False: Strongly Consistent write models require sacrifices in availability.

  • True
  • False

Question: Options to provide availability in a CQRS system include:

Note: Make sure you select all of the correct options—there may be more than one!

  • Disabling writes, but continuing to allow reads if the write model fails.
  • Disabling reads, but continuing to allow writes if the read model fails.
  • Using cached data for the read model when current data is unavailable.
  • Disabling reads and writes and providing an error message instead.
  • Sharding the writes so that only a subset of users are affected by an outage.

Cost of CQRS Review

Question: True or False: CQRS takes concepts that would commonly be isolated in a single large class or model, and spreads them across multiple smaller classes or models.

  • True
  • False

Question: CQRS is often considered to be more complex because:

  • The large complex domain models make it cumbersome.
  • It requires additional infrastructure in the form of a message bus.
  • It is eventually consistent by design.
  • Programming is hard.

Question: True or False: The Eventual Consistency introduced by CQRS based systems was actually always there. CQRS just makes it more explicit.

  • True
  • False

Question: Some concrete costs associated with using CQRS and Event Sourcing include:

Note: Make sure you select all of the correct options—there may be more than one!

  • More classes and objects.
  • Multiple versions of events must be kept.
  • Eventually Consistent write models.
  • Limited ability to draw insight from the data.
  • More storage space required.

Question: When data between the read and write model is out of sync, we can:

  • Write a script that extracts the state from the read model and updates the events in the write model.
  • Delete the write model, and rebuild it from the read model.
  • Restore from a backup.
  • Delete the read model, and rebuild it from the write model.

Case Study: Reactive BBQ Scenarios

Question: Some possible reasons this problem exists include:

  • The database (tables, indexes etc) was optimized for day to day operation, not for the reports, so the reports are overly expensive.
  • The reports create contention in the database in the form of read locks.
  • The reports create contention on the database hardware in the form of memory/cpu/disk usage.
  • All of the above
  • None of the above

Question: In the new system, they could avoid this problem by:

  • Getting a better database.
  • Allocating more hardware to the database.
  • Leveraging the event log to build a read model(s) for the reports.
  • All of the above
  • None of the above

Question: True or False: The data on the screen must be strongly consistent to avoid potential errors in the order.

  • True
  • False

Question: In order to ensure that the information on the screen is always available we could:

  • Create a read model which updates the screen, and a separate model which prints out a ticket. If the screen fails we can fallback to the ticket.
  • Replicate the data to multiple locations by consuming the order event log multiple times.
  • Isolate failures by separating screen data into it’s own independent microservice.
  • All of the above
  • None of the above

Question: Which parts of the existing system would have already experienced Eventual Consistency?

  • The host looks at a paper printout of upcoming reservations.
  • The host creates a new reservation after a customer phones in.
  • The customer creates a new reservation on the website.
  • The customer makes a change to an existing reservation on the website.
  • The host looks at an on screen display of current reservations.

Question: Which parts of the new system will need strong consistency (given that they have expressed a desire for consistency)?

  • The host looks at a paper printout of upcoming reservations.
  • The host creates a new reservation after a customer phones in.
  • The customer creates a new reservation on the website.
  • The customer makes a change to an existing reservation on the website.
  • The host looks at an on screen display of current reservations.

Final Exam

Question: Scalable Games is an online gaming company. They have built a new game that they are hoping will have millions of users.

The game they are building is a strategy title where users can play asychronously. A user may create their kingdom, and attack other users, but those attacks are carried out without requiring input from either user.

To achieve this, when a user wants to attack another user, they submit a request to the server to perform the attack. The server will acknowledge that it has received the request, but the actual execution of the request will happen asynchronously. The request will be added to a queue, and when the server is ready, it will perform the attack and then notify both users once it has determined the result.

The game server is leveraging a(n) _______ sourced model.

Answer: Command

Question: CQRS Auto is a automobile trading company formed in the 1980s by four partners (Christa, Quentin, Rhonda, and Samuel). They have since grown to be one of the largest auto traders in the nation.

The company allows users to post an advertisement for a vehicle that they want to sell. They can create the ad, attach pictures, add descriptions, set the price etc.

Once their ad has been created, it will be asynchronously added to the CQRS Auto website. On the website, other users can filter the vehicles, compare them, and look at the details.

When creating an ad, users would be interfacing with the _______ model, or the _______ side of the CQRS system.

Answer: Write

When viewing ads, users would be interfacing with the _______ model, or the _______ side of the CQRS system.

Answer: Read

Question: Saga Electronics is an online retailer focusing on Electronics.

A critical part of their business is the payment service. They use a third party payment processor to handle all transactions, however, it is still critical that they keep internal records which are then reconciled with the records from the payment processor.

In order to do this, each time a payment is made, they enter the details of that payment into a log. This log can then be reconciled against any logs that come back from the payment processor. If a discrepancy is found then they will have to perform an audit to determine why there is a difference.

The integrity of this log is critical. For that reason, they require that the log be append only. If a correction needs to be made, then they will make that correction by adding an additional log entry, rather than editing an existing one.

Saga Electronics could leverage _______ to maintain their log.

Answer: Event Sourcing

Question: Spectrum Messages has created an online messaging platform.

One of the features of their platform is the ability to broadcast messages to a large number of users. A user can create a message that will be shared with a group, rather than an individual.

When a group message is sent, there is no guarantee that every receiver will be online at the time. They may have their phone turned off, the app may be disabled, or they may not have internet access.

The sender can create their messages using _______ Consistency.

Answer: Strong Consistency

The receivers will receive the messages using _______ Consistency.

Answer: Eventual Consistency

Question: Consistent Fitness has built a wearable fitness tracker. Users push data from their fitness tracker up to the company servers. This data is then stored in a raw form.

One of the goals of the company is to create a series of rich insights about their users. These insights are presented to the users through a dashboard. They allow users to learn things about their own fitness habits such as how often they exercise in a week, how their heart rate changes when they exercise etc.

They have a series of asynchronous processes which will consume the raw data, and aggregate it in various ways. This allows them to take the raw user data, and create new insights. And because they always have access to the raw data, these insights can be retroactive.

Consistent Fitness is levaragine what technique?

Answer: CQRS

Conclusion:

We hope you know the correct answers to Reactive Architecture: CQRS & Event Sourcing If Queslers helped you to find out the correct answers then make sure to bookmark our site for more Course Quiz Answers.

If the options are not the same then make sure to let us know by leaving it in the comments below.

Course Review:

In our experience, we suggest you enroll in this and gain some new skills from Professionals completely free and we assure you will be worth it.

This course is available on Cognitive Class for free, if you are stuck anywhere between quiz or graded assessment quiz, just visit Queslers to get all Quiz Answers and Coding Solutions.

More Courses Quiz Answers >>

Building Cloud Native and Multicloud Applications Quiz Answers

Accelerating Deep Learning with GPUs Quiz Answers

Blockchain Essentials Cognitive Class Quiz Answers

Leave a Reply

Your email address will not be published.