Sunday, December 11, 2022

Google Codelab Format

 

The Problem

The Solution

Landing page where codelabs are hosted
Sample codelab
Confluence Group/Space landing page

Imitation is the sincerest form of flattery :)

The Execution

Install Software

Configure Go Environment

## not required if you’re only using Go modules 
export GOPATH=$HOME/go
export GOROOT=/usr/local/go
## required
export PATH=$PATH:$HOME/go/bin

Manage claat

chmod u+x claat

Setup the Landing Page

git clone https://github.com/googlecodelabs/tools
## navigate to folder
cd site/
## install dependencies
npm install
npm install -g gulp-cli
gulp serve
Running via Terminal
Codelab landing page running locally

Write a Sample Codelab

## create codelabs folder
mkdir codelabs
## go into directory
cd codelabs/
## create assets folder
mkdir assets
tools
|-- site
|--|-- codelabs
|--|--|-- assets
summary: How to Write a Codelab
id: how-to-write-a-codelab
categories: Sample
tags: medium
status: Published
authors: Zarin
Feedback Link: https://zarin.io

# How to Write a Codelab
<!-- ------------------------ -->
## Overview
Duration: 1

### What You’ll Learn
- how to set the amount of time each slide will take to finish
- how to include code snippets
- how to hyperlink items
- how to include images
- other stuff

<!-- ------------------------ -->
## Setting Duration
Duration: 2

To indicate how long each slide will take to go through, set the `Duration` under each Heading 2 (i.e. `##`) to an integer.
The integers refer to minutes. If you set `Duration: 4` then a particular slide will take 4 minutes to complete.

The total time will automatically be calculated for you and will be displayed on the codelab once you create it.

<!-- ------------------------ -->
## Code Snippets
Duration: 3

To include code snippets you can do a few things.
- Inline highlighting can be done using the tiny tick mark on your keyboard: "`"
- Embedded code

### JavaScript

```javascript
{
key1: "string",
key2: integer,
key3: "string"
}
```

### Java

```java
for (statement 1; statement 2; statement 3) {
// code block to be executed
}
```

<!-- ------------------------ -->
## Hyperlinking and Embedded Images
Duration: 1
### Hyperlinking
[Youtube - Halsey Playlists](https://www.youtube.com/user/iamhalsey/playlists)

### Images
![alt-text-here](assets/puppy.jpg)

<!-- ------------------------ -->
## Other Stuff
Duration: 1

Checkout the official documentation here: [Codelab Formatting Guide](https://github.com/googlecodelabs/tools/blob/master/FORMAT-GUIDE.md)
## go into codelabs folder
cd codelabs
## export md to html
claat export how-to-write-a-codelab.md
Output for claat command
Filesystem after running claat export within codelabs directory
## go back to site folder
cd ..
## re-run command
gulp serve --codelabs-dir=codelabs
Landing page now rendering newly written codelab
Sample codelab on desktop
Sample codelab on iPhone 6/7

Categorize Codelabs

@include codelab-card(['sample'], #FC0023, 'sample.svg');
gulp serve --codelabs-dir=codelabs
Your codelab formatted nicely
“Web” is a predefined Category, and “Sample” is the one we just created

Create Multiple Homepages (Views)

{
"title": "Medium Articles",
"description": "Hosting codelabs that have been used to write Medium articles",
"logoUrl": "/medium/medium.png",
"tags": ["medium"],
"exclude": [
".*-about$",
"^lang-.*"
]
}
summary: How to Write a Codelab
id: how-to-write-a-codelab
categories: Sample
tags: medium
status: Published
authors: Zarin
Feedback Link: https://zarin.io
You should see the Medium view appear in the drop-down
Example of associating a codelab to a view

The Response

Publishing Codelabs

Next Steps

Saturday, November 26, 2022

10 Best Practices For Using Kafka In Your Architecture

 

Key lessons I have learned While Using Kafka

Apache Kafka, also known as Kafka, is an enterprise-level messaging and streaming broker system. Kafka is a great technology to use to architect and build real-time data pipelines and streaming applications.


I highly recommend the architects to familiarise themselves with the Kafka ecosystem, in particular on the concepts of Kafka cluster, broker, topics, partitions, consumer, producer and offsets.

Article Aim

This article will highlight 12 of the important lessons I have learned whilst using Kafka.

  1. To enable parallel processing of messages, create multiple partitions in a topic. This enables multiple consumers to process the messages in parallel. Each partition can be consumed by only one consumer within a consumer group. So, if there are multiple consumers in a consumer group, they can consume messages from different partitions. Therefore, if we want to parallelize the consumption of the messages, create multiple partitions in a topic.
  2. Each message goes to every consumer group that has subscribed to a topic/partition, but within a group, it goes to only one consumer. Therefore, all  that have subscribed to the topic get the messages but only one consumer within a consumer group gets a message from a partition. So if you want to broadcast the message to multiple consumers, assign them different .
  3. The default setting of a message size in Kafka is 1MB. Messages can be compressed before they are delivered to Kafka. To store more data in a single topic, we can create multiple partitions across multiple servers
  4. Ensure the messages that are required to be published or consumed are serializable. Take special care of date time and nested structures.
  5. Use the function seek(TopicPartition, long) to specify the new position.
  6. If we are designing an application where the order of messages is important and we want the order of messages to be guaranteed, then use the same Partition Id in all of the messages. The reason is that the ordering guarantee applies at the partition level. So, if you have more than one partition in a topic, you’ll need to ensure the messages you are required to appear in order to have the same partition Id. All messages that are pushed into a partition of a topic will be ordered correctly if they have the same partition ID.
  7. If we want global ordering across all topics, use a single partition topic.
  8. Keep your logs manageable and monitor disk space on regular basis.
  9. To design a durable system, ensure a high replication factor is set in the Kafka setting. Kafka replicates the log for each topic’s partitions across multiple servers. When a server fails, this allows automatic failover to these replicas as the messages remain available in the presence of failures. We can set the replication factor on a topic-by-topic basis. Plus, we can set the producer batch size to 1. It will ensure each message is saved to the disk and the messages are not flushed in batches. This will impact the performance. For durable and highly available systems, it’s important to have high topic replication. Usually, a minimum of 3 brokers is recommended for reliable failover.
  10. If we want to delete older messages, use compacted topics where older events for a key are removed as and when newer events are published to the topic.
  11. To secure Kafka, use TLS client certificates, encrypt the messages, and add user permissions.
  12. We could also Java DSL or Kafka’s SQL-like streaming language to create and process the streams of data that are stored in Kafka.

Summary

This article highlighted 10 important lessons I have learned whilst using Kafka.

Deduplicating Data on the Databricks Lakehouse: Making joins, BI, and AI queries “safe by default.”

  Imagine this: your manager asks the AI analytics tool: "What were our top-selling products last quarter?" The AI generates perfe...