0
0
Microservicessystem_design~10 mins

Event schema design in Microservices - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a table for storing event data with an event ID as the primary key.

Microservices
CREATE TABLE events (event_id [1] PRIMARY KEY, event_name VARCHAR(100));
Drag options to blanks, or click blank then click option'
AINT
BVARCHAR(50)
CDATE
DTEXT
Attempts:
3 left
💡 Hint
Common Mistakes
Using VARCHAR for event_id which is less efficient for keys.
Using DATE type which is not suitable for IDs.
2fill in blank
medium

Complete the code to add a timestamp column to record when the event occurred.

Microservices
ALTER TABLE events ADD COLUMN event_time [1];
Drag options to blanks, or click blank then click option'
ATIMESTAMP
BINT
CVARCHAR(50)
DBOOLEAN
Attempts:
3 left
💡 Hint
Common Mistakes
Using INT which cannot store date/time.
Using BOOLEAN which is only true/false.
3fill in blank
hard

Fix the error in the event schema by choosing the correct data type for event payload storage.

Microservices
CREATE TABLE event_payloads (payload_id INT PRIMARY KEY, event_id INT, payload [1]);
Drag options to blanks, or click blank then click option'
AINT
BTEXT
CVARCHAR(255)
DBOOLEAN
Attempts:
3 left
💡 Hint
Common Mistakes
Using VARCHAR(255) which may be too short for large payloads.
Using INT or BOOLEAN which cannot store text.
4fill in blank
hard

Fill both blanks to create a foreign key relationship between event_payloads and events tables.

Microservices
ALTER TABLE event_payloads ADD CONSTRAINT fk_event FOREIGN KEY ([1]) REFERENCES [2](event_id);
Drag options to blanks, or click blank then click option'
Aevent_id
Bevents
Cpayload_id
Devent_payloads
Attempts:
3 left
💡 Hint
Common Mistakes
Using payload_id as foreign key which is incorrect.
Referencing the wrong table.
5fill in blank
hard

Fill all three blanks to create an index on event_time and event_name for faster queries.

Microservices
CREATE INDEX idx_[1] ON events ([2], [3]);
Drag options to blanks, or click blank then click option'
Atime_name
Bevent_time
Cevent_name
Devent_id
Attempts:
3 left
💡 Hint
Common Mistakes
Using event_id in the index which is already primary key.
Choosing a non-descriptive index name.