<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Martel Richard on Medium]]></title>
        <description><![CDATA[Stories by Martel Richard on Medium]]></description>
        <link>https://medium.com/@richardmr36?source=rss-1b602f4c28e1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Stories by Martel Richard on Medium</title>
            <link>https://medium.com/@richardmr36?source=rss-1b602f4c28e1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 27 Nov 2026 17:45:40 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@richardmr36/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Correlation in logging]]></title>
            <link>https://richardmr36.medium.com/correlation-in-logging-b19f752cb751?source=rss-1b602f4c28e1------2</link>
            <guid isPermaLink="false">https://medium.com/p/b19f752cb751</guid>
            <category><![CDATA[logging]]></category>
            <category><![CDATA[mdc]]></category>
            <category><![CDATA[tracing]]></category>
            <dc:creator><![CDATA[Martel Richard]]></dc:creator>
            <pubDate>Tue, 10 Jun 2025 10:54:42 GMT</pubDate>
            <atom:updated>2025-06-10T10:54:42.144Z</atom:updated>
            <content:encoded><![CDATA[<h3>What is Correlation in logging?</h3><p>It refers to the practice of linking together log entries that are part of the same transaction, user session, request, or workflow, even if those entries are generated by different components or services in a distributed system.</p><h3>Why does it matter?</h3><p>In modern applications, especially microservices or cloud-based systems, a single user action might trigger a cascade of events across multiple services. Without correlation, it’s hard to trace the full path of that action through the system.</p><h3>How Correlation Works</h3><p>A correlation ID (or trace ID) is a unique identifier that is:</p><ol><li>Generated at the start of a request or transaction.</li><li>Passed along to all components or services involved.</li><li>Logged with every log entry related to that request.</li></ol><p>This way, you can filter or search logs by the correlation ID to see the full picture.</p><pre>2025-05-19 10:15:21.370 INFO [correlation-id=3b9c39ab-ad6e-47c4-b6ee-dc0ee34ff807] [thread-id=boundedElastic-1] com.app.service.LoginService:10 - User logged in</pre><h3>Log4j support for correlation</h3><p>Log4j (Logging for Java) is a standard logging library in Java. It has MDC that allows you to enrich your log messages with contextual information that can be very helpful for debugging and tracing execution, especially in multi-threaded or distributed applications.</p><h3>What is MDC?</h3><p>Mapped Diagnostic Context is essentially a thread-local map where you can store key-value pairs. These values can then be included in your log output using a pattern layout. Since it’s thread-local, each thread has its own copy of the MDC data, which avoids interference between thread.</p><p>For example, imagine you’re handling multiple user requests in a web application. Each request is processed in a separate thread. You might want to log the user ID, session ID, or transaction ID with every log message related to that request. MDC makes this easy.</p><h3>How to use MDC?</h3><p>com.myapp.controller.MyController.java</p><pre>try {<br>  MDC.put(&quot;correlation-id&quot;, UUID.randomUUID().toString());<br>  log.info(&quot;Testing contextual logging&quot;);<br>}<br>finally {<br>  MDC.remove(&quot;correlation-id&quot;);<br>}</pre><p>log4j2.xml</p><pre>&lt;PatternLayout pattern=&quot;%d{yyyy-MM-dd HH:mm:ss.SSS} %5p [correlation-id=%X{correlation-id}] [thread-id=%t] %logger{36} - %m%n%xwEx&quot;/&gt;</pre><p>NOTE: When you use %X followed by a key in curly braces, like %X{key}, it will output the value associated with that key from the MDC. If you use %X without a key, it will output all entries in the MDC, in the format key1=value1, key2=value2, ...</p><p>Log Output</p><pre>2025-05-22 12:56:14.216  INFO [correlation-id=1b4a4f98-54b1-4951-b3e5-7c7ca742564b] [thread-id=http-nio-9052-exec-1] com.myapp.controller.MyController - Testing contextual logging</pre><h3>Caveats with MDC</h3><p>MDC uses thread-local storage, meaning the context is tied to the current thread. So it has the caveats same as the ThreadLocal.</p><p>Thread pools If a thread is reused and MDC is not cleared, old context data may leak into unrelated requests and lead to inconsistent logging. So always clear MDC after use.</p><p>Async processing MDC data may not propagate to new threads unless explicitly passed.</p><h3>Context Propogation</h3><p>In asynchronous or reactive programming like Project Reactor, context (like ThreadLocal values used for logging or tracing) can be lost when execution hops between threads. This breaks features like MDC logging or distributed tracing. In such cases, the context has to be propogated across threads. <a href="https://spring.io/blog/2023/03/28/context-propagation-with-project-reactor-1-the-basics">Take a look at this spring blog to understand more on this!</a></p><p>In a nutshell, context propogation bridges ThreadLocal and Reactor Context and allows MDC to work to work seamlessly in reactive flows. This also helps tools like Micrometer and other tracing libraries and enables distributed tracing in the reactive world.</p><p><a href="https://medium.com/javarevisited/demystifying-context-propagation-in-spring-web-flux-with-threadlocalaccessor-contextregistry-mdc-c3740e0b990e">Check out this Medium article.</a> The author explains context propagation clearly with practical examples.</p><h3>References</h3><ul><li><a href="https://micrometer.io/docs/contextPropagation">https://micrometer.io/docs/contextPropagation</a></li><li><a href="https://www.baeldung.com/mdc-in-log4j-2-logback">https://www.baeldung.com/mdc-in-log4j-2-logback</a></li><li><a href="https://medium.com/asyncparadigm/logging-in-a-multithreaded-environment-and-with-completablefuture-construct-using-mdc-1c34c691cef0">https://medium.com/asyncparadigm/logging-in-a-multithreaded-environment-and-with-completablefuture-construct-using-mdc-1c34c691cef0</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b19f752cb751" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Collation in Database — What you need to know]]></title>
            <link>https://richardmr36.medium.com/collation-in-database-what-you-need-to-know-65a77d4f5e0a?source=rss-1b602f4c28e1------2</link>
            <guid isPermaLink="false">https://medium.com/p/65a77d4f5e0a</guid>
            <category><![CDATA[collation]]></category>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[database]]></category>
            <dc:creator><![CDATA[Martel Richard]]></dc:creator>
            <pubDate>Tue, 20 May 2025 13:27:49 GMT</pubDate>
            <atom:updated>2025-05-20T13:27:49.597Z</atom:updated>
            <content:encoded><![CDATA[<h3>Collation in Database — What you need to know</h3><h3>What is Collation?</h3><p>Collation refers to a set of rules that determine how data is sorted and compared. Collation settings specify the correct character sequence, case sensitivity, accent marks, character width and the characters used in comparison operations, such as equality and inequality.</p><h3>How does this affect the data?</h3><h4>1. Character data sort order</h4><p>This specifies how string data is sequenced. For example, whether ‘a’ comes before ‘b’.</p><h4>2. Case sensitivity</h4><p>This determines whether ‘A’ and ‘a’ are considered the same.</p><h4>3. Accent sensitivity</h4><p>This determines whether ‘a’ and ‘á’ are considered the same.</p><h4>4. Kana Sensitivity</h4><p>This determines whether two characters that look the same but are represented differently in Kana (a Japanese script) are treated as equal.</p><h4>5. Width sensitivity</h4><p>This determines whether a single-byte character (half-width) and the same character represented as a double-byte character (full-width) are treated as equal.</p><h3>Where do you specify the collation?</h3><p>Collation can be specified at different levels depending on the specific database system. For example, in SQL Server, it can be specified at:</p><ol><li>Server level</li><li>Database level</li><li>Column level</li><li>Expression (SQL Query) level</li></ol><p>The above levels are mentioned in the descending order of hierarchy i.e. when you create a database, you specify the default collation for the database. Every column in the database that uses <em>character data types</em> has a collation. If not specified, the column uses the default collation of the database.</p><h3>How collation affects the query results?</h3><p>For example, the default collation in SQL Server is</p><blockquote><em>SQL_Latin1_General_CP1_CI_AS</em></blockquote><p>The elements of this collation name represent the following.</p><p><strong>SQL</strong> — This prefix means that the collation is a SQL Server collation.</p><p><strong>Latin1_General</strong> — This is the base collation, which defines the rules that are used for sorting and comparing characters within the Latin1 character set.</p><p><strong>CP1</strong> — This stands for <a href="https://en.wikipedia.org/wiki/Windows-1252">Code Page 1252</a>, which is a character encoding of the Latin alphabet, used by default in the legacy components of Microsoft Windows in English and some other Western languages.</p><p><strong>CI</strong> — This stands for Case Insensitive. This means that the SQL Server does not consider case during comparison. For example, ‘A’ and ‘a’ are considered to be the same.</p><p><strong>AS</strong> — This stands for Accent Sensitive. This means that accented characters and unaccented characters are considered to be different. For example, ‘a’ and ‘á’ are considered to be different.</p><p>Overall, SQL_Latin1_General_CP1_CI_AS is a SQL Server collation that is case insensitive and accent sensitive, using the Latin1 General rules and the 1252 Code Page. This is a commonly used collation in the English language for SQL Server.</p><h3>How to check your collation settings in SQL Server</h3><p>You can determine the server’s character set in SQL Server by using the following SQL query.</p><pre>SELECT SERVERPROPERTY(&#39;Collation&#39;)</pre><p>If you need more information about the collation, you can use fn_helpcollations function which returns all the collations supported by your server.</p><pre>SELECT * FROM fn_helpcollations()</pre><h3>When characters cannot be represented in a given collation</h3><p>In the context of the SQL_Latin1_General_CP1_CI_AS collation in SQL Server, which is based on the Windows-1252 code page, certain characters from other scripts or languages that are not covered by Windows-1252 may not be saved correctly.</p><p>For example, characters from scripts such as Arabic, Hebrew, Cyrillic, Chinese, Japanese, Korean, and many others, cannot be properly represented in this collation. So, if you try to save a character like the Arabic letter “ج” or the Chinese character “汉” using this collation, such characters will be replaced with “?”.</p><p>Refer <a href="https://learn.microsoft.com/en-us/sql/relational-databases/collations/collation-and-unicode-support?view=sql-server-ver16#collation">Collation in SQL Server</a> to know more on various collation rules and levels.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=65a77d4f5e0a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction to Graph Database]]></title>
            <link>https://richardmr36.medium.com/introduction-to-graph-database-eebb5d17c2e5?source=rss-1b602f4c28e1------2</link>
            <guid isPermaLink="false">https://medium.com/p/eebb5d17c2e5</guid>
            <category><![CDATA[database]]></category>
            <category><![CDATA[graphdb]]></category>
            <category><![CDATA[graph-database]]></category>
            <dc:creator><![CDATA[Martel Richard]]></dc:creator>
            <pubDate>Tue, 27 Nov 2018 17:01:25 GMT</pubDate>
            <atom:updated>2018-11-27T17:01:25.585Z</atom:updated>
            <content:encoded><![CDATA[<p>If you ask anybody what kind of database is used in your application, majority will say Relational Database. It has been the de facto standard for database that people go to when they start building an application and it usually suits their requirements. Relational database has been around since 80&#39;s and most of the world’s top enterprise applications uses it even today. It is still the best database to store structured data in the form of tables. Each row is uniquely identified by a primary key. We query data from relational database using SQL. For example,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/304/1*hw4QGe7exTz0uD0Ivloknw.png" /><figcaption>Table: Person</figcaption></figure><p>To query all male persons, below is the query,</p><p><em>SELECT * FROM PERSONS WHERE GENDER = ‘MALE’;</em></p><p>When the application grows bigger, a single table may not be sufficient to represent an entity as it’s attributes may also grow and data will be spread across tables in a normalized database. This is where the relationship between tables comes in.</p><p>Say there is another table Department</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/195/1*4tcu7ZkJAPW72xWNqrP-_A.png" /><figcaption>Table: Department</figcaption></figure><p>To associate a person to department, a foreign key dept_id will have to be introduced to persons table which is the primary key of departments table and it will be a one-to-one relationship.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/487/1*0rLYFw5OJB3sDzzW8hMkWw.png" /><figcaption>Table: Person with foreign key</figcaption></figure><p>When a person is associated with multiple departments, then it will be one-to-many or many-to-many relationships. This relationship is usually represented in another separate table with person_id and dept_id</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/261/1*fcw_o0YT6m_poxijKNunRw.png" /><figcaption>Table: Dept_Person</figcaption></figure><p>To retrieve data using SQL, a JOIN has to be used between tables. In case of may-to-many relationship, the query will be something like below to retrieve the person details with departments.</p><p><em>SELECT * FROM PERSON INNER JOIN DEPT_PERSON ON PERSON.ID = DEPT_PERSON.PERSON_ID</em></p><p>This is a simple example and when we include tens of departments, sub-departments, different portfolios, etc, just to represent the relationship between tables will be a nightmare and to query them using multiple JOIN will take a performance hit in relational database. Graph database essentially addresses this drawback.</p><p>Graph are basically a set of vertices connected by edges. In a graph database, each real world entity will be stored as a vertex and relationship between them will be represented in edges.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/381/1*pysxux_pD3czoxOUTe3K4Q.jpeg" /></figure><p>When a person is involved in multiple departments, simply have one more edge from that person vertex directing to the other department and be done with it. There is no overhead of having another column or table and maintaining them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/460/1*qpcXtM_eoHbGbsTJHeYIBA.jpeg" /></figure><p>Each vertex can have properties or attributes describing about it. Here each person vertex will have Name and Gender properties. Each edge will also have a label to denote the kind of relationship it has with the other entity. If there are more than one relationships between two entities, we can simply have two edges to the other entity denoting their relationships.</p><p>Querying in graph database will be something like below.</p><p><em>Graph g = GraphFactory.getIntance(“myfirstgraphdb”);</em></p><p><em>Vertex peter = g.addVertex(label:“Person”, name:“Peter”, gender:”Male”);</em></p><p><em>Vertex = publicRelations = g.addVertex(label:“Department”, name:“Public Relations”);</em></p><p><em>Vertex urbanDevelopment= g.addVertex(label:“Department”, name:“Urban Development”);</em></p><p><em>peter.addEdge(“Involved in”, publicRelations);</em></p><p><em>peter.addEdge(“Involved in”, urbanDevelopment);</em></p><p><em>To find Peter -&gt; g.find(name: “Peter”)</em></p><p><em>To filter with male gender -&gt; g.has(gender: “Male”)</em></p><p>These are just basic operations in graph database and there can be much more advanced querying available with filtering, sorting, etc. In essence, graph database beats the rigid nature of relational database and simply queries the data by traversing across the edges. There are many providers available for graph database and currently Neo4j provides an enterprise grade graph database with many salient features. There is also a free version with limited features available or you can try Tinkerpop, an Apache flavor of graph database to explore more on this.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eebb5d17c2e5" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>