Posts

Legacy Displacement

  "When faced with the need to replace existing software systems, organizations often fall into a cycle of half-completed technology replacements. Our experiences have taught us a series of patterns that allow us to break this cycle, relying on: a deliberate recognition of the desired outcomes of displacing the legacy software, breaking this displacement in parts, incrementally delivering these parts, and changing the culture of the organization to recognize that change is the unvarying reality...." https://martinfowler.com/articles/patterns-legacy-displacement/

HTTP/2 - HTTP/1

HTTP/1.1 assumes that a TCP connection should be kept open unless directly told to close. HTTP2 reduces latency by using multiplexing, compression and prioritization. An application level API would still create messages in the conventional HTTP formats, but the underlying layer converts the payload into binary (binary framing). HTTP/2 establishes a single connection object between the two machines. Within this connection there are multiple streams of data. Each stream consists of multiple messages in the familiar request/response format. Finally, each of these messages split into smaller units called frames. Multiplexing: Several requests and responses can run in parallel using a single TCP connection without blocking each other. This reduces processor and memory resources and the SSL handshakes. Stream prioritization feature allows developers to prioritize the requests by assigning a weight between 1 and 256 to each stream. The higher number indicates higher priority.  serve...

Some thoughts on Conway's law

Human beings are complex social animals. Rome was not built in a day. Address the issues that can be addressed first. Create independent subsystems to reduce the communication cost. Read more:  https://medium.com/@Alibaba_Cloud/conways-law-a-theoretical-basis-for-the-microservice-architecture-c666f7fcc66a

Java 9 Jigsaw - How to create modules

Image

Java 10 - type inference with var

Go to: https://blog.codefx.org/java/java-10-var-type-inference/

Java - Replace traditional for loops with IntStreams

Go to: https://www.deadcoderising.com/2015-05-19-java-8-replace-traditional-for-loops-with-intstreams/

Finagle

Build request: RequestBuilder requestBuilder = new RequestBuilder()   // custom class                 .withMethod(method)                 .withHeader(xxx, "xxx")                 .withPath(endpoint)                 .withParams(request.getPathParams())                 .withQueryParams(request.getQueryParams()); Service<Request, Response> restService = restServiceProvider.getService(serviceLabel); Finagle Call:         final Future<O> responseFuture = filter.apply(request, restService);         final O result         try {             result = Await.result(responseFuture, Duration.fromMilliseconds(config.getTotalRequestTimeout()));         } ca...

Java Optional - How to use correctly

How to use Java Optional correctly, what to avoid and good practices: https://dzone.com/articles/using-optional-correctly-is-not-optional

Spring boot - Conditional Bean Creation

@ConditionalOnBean(name = "otherNeededBean") The bean is only created, if the bean "otherNeededBean" already exist. @ConditionalOnMissingBean The bean is only created, if no other bean with the same name already exist. @ConditionalOnMissingBean(type = "alternativeBean") The bean is only created, if bean "alternativeBean" doesn't exist. Conditional based on Environment property Add proprty file to the Configuration class. @PropertySource("classpath:myspecific.properties") public class MySpecificConfiguration {} @ConditionalOnProperty(name = "email.notification", havingValue = "true") @Bean public MailService ... myspecific.properties: email.notification = true | false

Command Query Responsibility Segregation (CQRS)

"every method should either be a Command that performs an action or a Query that returns data. A Command cannot return data and a Query cannot change the data... it might be desirable to use two different data stores... this allows you to store the data in the read database as denormalised data... it allows you to scale the two different sides of your application separately..." More info:  https://culttt.com/2015/01/14/command-query-responsibility-segregation-cqrs/

Dzone Java Developer Roadmap 2019

Image
https://dzone.com/articles/the-2019-java-developer-roadmap

Git Merge vs. Rebase

"Merge creates a new “merge commit” in the target branch that ties together the histories of both branches. Merging is nice because it’s a non-destructive operation. The existing branches are not changed in any way. On the other hand, the target branch will have an extraneous merge commit every time you merge.  Rebase moves the entire source branch to begin on the tip of the target branch, effectively incorporating all of the new commits in target.  But, instead of using a merge commit, rebasing re-writes the project history by creating brand new commits for each commit in the original branch. You get a much cleaner project history and it eliminates the unnecessary merge commits. But, there are two trade-offs for this pristine commit history: safety and traceability. The Golden Rule of Rebasing: The golden rule of git rebase is to never use it on public branches. Rebase moves all of the commits in source onto the tip of target. The problem is that this only happened ...

Java Keytool, Keys and Certificates

app-1 will provide a copy of his public key to app-2 and signs the communication with its private key. Step 1: app-1 creates private/public key pair in its keystore: $ keytool -genkey -alias "app-1-key" -keystore app-1.jks Verify: $ keytool -v -list -keystore app-1.jks Step 2: app-1 generates a certificate file from its private keystore: $ keytool -export -alias "app-1-key" -file app-1.cer -keystore app-1.jks Step 3: app-2 imports the public key of app-1 into its keystore: $ keytool -import -alias "app-1-publickey" -file app-1.cer -keystore app-2-publickey.store

PI Mutation Tests

Faults (or mutations) are automatically seeded into your code, then your tests are run. If your tests fail then the mutation is killed, if your tests pass then the mutation lived. https://pitest.org/ Example Method: isPositive Actual implementation:   if (number >= 0) return true; Following test will pass:   assertEquals(true, xxx.isPositive(10)); But fail for following code mutation:   if (number > 0) return true; To kill the mutation, the unit test should test boundaries:   assertEquals(true, xxx.isPositive(10));   assertEquals(true, xxx.isPositive(0)); See:  https://www.mkyong.com/maven/maven-pitest-mutation-testing-example/

Mutual TLS - Easy explained

A puts an envelope in a box, locks the box with his key and sends it to B. The box can't be opened on the way, since it is locked. B receives the box, and accepts to view it. But can't open the box neither, since it is locked. B lockes the box again, this time with his own lock and sends it back to A. The box is now locked with 2 locks, one from A, and one from B. A receives the box and realizes, that B has accepted the communication by locking the box with his lock.  A can now remove his lock and send the box back to B.  The box still can't be opened by anyone other than B. B receives the box with his lock and can now open the box with his own key and open the envelope sent by A originally. For A and B to trust each others locks (certificates), a Certificate Authority (CA) must approve both certificates. See also: https://www.codeproject.com/Articles/326574/An-Introduction-to-Mutual-SSL-Authentication

Log-based Change-Data-Capture (CDC) and Kafka Connect

"Kafka Connect provides scalable and resilient integration between Kafka and other systems. The Confluent JDBC Connector for Kafka Connect enables you to stream data to and from Kafka and any RDBMS that supports JDBC. ... CDC basically enables you to stream every single event from a database into Kafka. Broadly put, relational databases use a transaction log ( redo log depending on DB flavour), to which every event in the database is written. Update a row, insert a row, delete a row – it all goes to the database’s transaction log..." Read more:  https://www.confluent.io/blog/no-more-silos-how-to-integrate-your-databases-with-apache-kafka-and-cdc See also  https://www.oracle.com/middleware/data-integration/goldengate/big-data/

Forward Proxy -> Reverse Proxy

"The difference between a forward and reverse proxy is subtle but important. A simplified way to sum it up would be to say that a forward proxy sits in front of a client and ensures that no origin server ever communicates directly with that specific client. On the other hand, a reverse proxy sits in front of an origin server and ensures that no client ever communicates directly with that origin server..." Read more here:  https://www.cloudflare.com/learning/cdn/glossary/reverse-proxy/

OWASP Web Top 10 2017

Image
OWASP Web Top 10 2017 and what has changed compare to 2010? Go to link:  https://www.owasp.org/images/7/72/OWASP_Top_10-2017_%28en%29.pdf.pdf Source: www.owasp.org

REST Endpoint: Consume / Produce JSON/XML

Image
Import Jackson Data format: Annotate the REST method to consume and produce the desired format(s): In HTTP Request header, set attribute: Content-Type  to application/json|xml to indicate the body format Accept  to application/json|xml to indicate the desired response format

Java 8

https://howtodoinjava.com/java-8-tutorial/