Bird
Raised Fist0
Kafkadevops~20 mins

Confluent Cloud overview in Kafka - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Confluent Cloud Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
What is the output of this Kafka producer code snippet in Confluent Cloud?

Consider this Kafka producer code snippet that sends a message to a topic in Confluent Cloud. What will be printed after successful message delivery?

Kafka
from confluent_kafka import Producer

conf = {'bootstrap.servers': 'pkc-xyz.us-west1.gcp.confluent.cloud:9092',
        'security.protocol': 'SASL_SSL',
        'sasl.mechanisms': 'PLAIN',
        'sasl.username': 'API_KEY',
        'sasl.password': 'API_SECRET'}

producer = Producer(conf)

def delivery_report(err, msg):
    if err is not None:
        print(f'Message delivery failed: {err}')
    else:
        print(f'Message delivered to {msg.topic()} [{msg.partition()}]')

producer.produce('my_topic', value='value1', callback=delivery_report)
producer.flush()
AMessage delivery failed: Broker not available
BMessage delivered to my_topic [0]
CMessage delivered to my_topic [1]
DNo output printed
Attempts:
2 left
💡 Hint

Think about the default partition assignment when no partition is specified.

🧠 Conceptual
intermediate
1:30remaining
Which feature of Confluent Cloud ensures data is encrypted during transit?

Confluent Cloud provides several security features. Which one specifically ensures that data sent between clients and the cloud is encrypted?

ASASL_SSL
BSchema Registry
CKafka Connect
DKafka Streams
Attempts:
2 left
💡 Hint

Look for the protocol that combines authentication and encryption.

🔧 Debug
advanced
2:30remaining
Why does this Kafka consumer in Confluent Cloud fail to receive messages?

Review the following consumer code snippet. It connects to Confluent Cloud but does not receive any messages. What is the most likely cause?

Kafka
from confluent_kafka import Consumer

conf = {'bootstrap.servers': 'pkc-xyz.us-west1.gcp.confluent.cloud:9092',
        'security.protocol': 'SASL_SSL',
        'sasl.mechanisms': 'PLAIN',
        'sasl.username': 'API_KEY',
        'sasl.password': 'API_SECRET',
        'group.id': 'my_group',
        'auto.offset.reset': 'earliest'}

consumer = Consumer(conf)
consumer.subscribe(['my_topic'])

msg = consumer.poll(1.0)
if msg is None:
    print('No message received')
elif msg.error():
    print(f'Error: {msg.error()}')
else:
    print(f'Received message: {msg.value().decode("utf-8")}')

consumer.close()
AThe consumer is not polling long enough to receive messages
BThe consumer group ID is missing or incorrect
CThe topic name is misspelled in subscribe()
DThe API key or secret is invalid
Attempts:
2 left
💡 Hint

Notice that poll() is called only once with a 1.0 second timeout.

📝 Syntax
advanced
1:30remaining
What error does this Confluent Cloud Kafka producer code raise?

Examine the following code snippet. What error will it raise when run?

Kafka
from confluent_kafka import Producer

conf = {'bootstrap.servers': 'pkc-xyz.us-west1.gcp.confluent.cloud:9092',
        'security.protocol': 'SASL_SSL',
        'sasl.mechanisms': 'PLAIN',
        'sasl.username': 'API_KEY',
        'sasl.password': 'API_SECRET'}

producer = Producer(conf)

# Missing required argument 'value'
producer.produce('my_topic', key='key1')
producer.flush()
ATypeError: produce() missing 1 required positional argument: 'value'
BValueError: Topic name cannot be empty
CRuntimeError: Producer not initialized
DNo error, message sent with empty value
Attempts:
2 left
💡 Hint

Check the required parameters for the produce() method.

🚀 Application
expert
1:00remaining
How many partitions will the topic have after this Confluent Cloud CLI command?

You run this command to create a topic in Confluent Cloud:

ccloud kafka topic create my_topic --partitions 5 --config retention.ms=604800000

How many partitions will my_topic have?

A10
B1
C5
D0
Attempts:
2 left
💡 Hint

The --partitions flag sets the number of partitions.

Practice

(1/5)
1. What is the main purpose of Confluent Cloud in Kafka usage?
easy
A. It provides a managed Kafka service for easy data streaming.
B. It is a tool to write SQL queries on Kafka topics.
C. It is a database for storing Kafka messages permanently.
D. It is a programming language for Kafka applications.

Solution

  1. Step 1: Understand Confluent Cloud's role

    Confluent Cloud is described as a managed Kafka service that simplifies data streaming.
  2. Step 2: Compare options with this role

    Only It provides a managed Kafka service for easy data streaming. matches this description; others describe unrelated tools or concepts.
  3. Final Answer:

    It provides a managed Kafka service for easy data streaming. -> Option A
  4. Quick Check:

    Managed Kafka service = It provides a managed Kafka service for easy data streaming. [OK]
Hint: Remember: Confluent Cloud manages Kafka for you [OK]
Common Mistakes:
  • Confusing Confluent Cloud with a database
  • Thinking it is a programming language
  • Assuming it runs SQL queries directly
2. Which of the following is the correct way to describe a Kafka topic in Confluent Cloud?
easy
A. A topic is a user account in Confluent Cloud.
B. A topic is a programming function to send messages.
C. A topic is a type of database index.
D. A topic is a place where messages are stored and organized.

Solution

  1. Step 1: Define Kafka topic concept

    A Kafka topic is a category or feed name to which messages are published and stored.
  2. Step 2: Match definition to options

    A topic is a place where messages are stored and organized. correctly states that a topic stores and organizes messages; others are incorrect.
  3. Final Answer:

    A topic is a place where messages are stored and organized. -> Option D
  4. Quick Check:

    Topic = message storage location [OK]
Hint: Topics hold messages, not functions or users [OK]
Common Mistakes:
  • Confusing topics with user accounts
  • Thinking topics are functions or indexes
  • Mixing topics with database concepts
3. Given the following code snippet for producing a message in Confluent Cloud Kafka client:
producer.produce(topic='orders', value='order123')

What happens when this code runs successfully?
medium
A. The 'orders' topic is deleted.
B. The message 'order123' is sent to the 'orders' topic.
C. The producer client shuts down.
D. An error occurs because 'value' must be a number.

Solution

  1. Step 1: Understand produce method

    The produce method sends a message to a specified topic with the given value.
  2. Step 2: Analyze the code behavior

    Here, 'order123' is sent as a message to the 'orders' topic; no deletion or shutdown occurs.
  3. Final Answer:

    The message 'order123' is sent to the 'orders' topic. -> Option B
  4. Quick Check:

    Produce sends message to topic [OK]
Hint: Produce sends data to topic, no deletion or shutdown [OK]
Common Mistakes:
  • Thinking produce deletes topics
  • Assuming value must be numeric
  • Confusing produce with client shutdown
4. You wrote this code to consume messages from a Confluent Cloud topic:
consumer.subscribe(['payments'])
message = consumer.poll(1.0)
print(message.value())

But you get an error: 'NoneType' object has no attribute 'value'. What is the likely cause?
medium
A. The print statement syntax is incorrect.
B. The topic 'payments' does not exist.
C. No messages were available to consume during poll timeout.
D. The consumer client was not connected to Confluent Cloud.

Solution

  1. Step 1: Understand poll method behavior

    poll returns None if no messages are received within the timeout period.
  2. Step 2: Analyze error cause

    Calling value() on None causes the error; this means no messages arrived during poll.
  3. Final Answer:

    No messages were available to consume during poll timeout. -> Option C
  4. Quick Check:

    poll returns None if no messages [OK]
Hint: poll returns None if no messages, check before accessing [OK]
Common Mistakes:
  • Assuming topic absence causes this error
  • Blaming connection issues without checking poll
  • Thinking print syntax is wrong
5. You want to create a Confluent Cloud Kafka topic that automatically deletes messages after 7 days. Which configuration should you apply when creating the topic?
hard
A. Set the topic's retention.ms to 604800000 (7 days in milliseconds).
B. Set the topic's cleanup.policy to 'compact'.
C. Set the topic's max.message.bytes to 7.
D. Set the topic's partitions to 7.

Solution

  1. Step 1: Understand retention.ms setting

    retention.ms controls how long messages are kept before deletion, in milliseconds.
  2. Step 2: Calculate 7 days in milliseconds

    7 days x 24 hours x 60 minutes x 60 seconds x 1000 = 604800000 ms.
  3. Step 3: Match configuration to requirement

    Setting retention.ms to 604800000 ensures messages delete after 7 days; other options do not control retention time.
  4. Final Answer:

    Set the topic's retention.ms to 604800000 (7 days in milliseconds). -> Option A
  5. Quick Check:

    retention.ms = 7 days in ms [OK]
Hint: Use retention.ms for message lifetime in ms [OK]
Common Mistakes:
  • Confusing cleanup.policy with retention time
  • Setting max.message.bytes instead of retention
  • Changing partitions unrelated to retention
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard