Microservices Architecture : Best Practices

The other day I came across this article: “Microservices Architecture: All the Best Practices You Need to Know“.  There’s been a lot said and written about the microservices architectures around the web.  But I like this article in particular, because it paints a more realistic picture, in my opinion.  Big parts of it are covering the “why?” part of the whole conversation, and it presents a balanced view of pros and cons, as well as several approaches to solving the problems.

This is very refreshing after tonnes of “Microservices are amazing, and are the best thing since sliced bread” and “Microservices is nothing but hype and bubble” coverage out there.

Encrypt MySQL data using AES technique

I came across this blog post from a while back, which demonstrates how to use AES encryption for the data in MySQL database.

INSERT into user (first_name, address) VALUES (AES_ENCRYPT('Obama', 'usa2010'),AES_ENCRYPT('Obama', 'usa2010'));
SELECT AES_DECRYPT(first_name, 'usa2010'), AES_DECRYPT(address, 'usa2010') from user;

This seems rather easy and straightforward (apart from a little calculation one needs to do for the VARBINARY field types).  The only thing that I’m concerned about is whether the encryption keys will be visible in the MySQL process list (as in “SHOW FULL PROCESSLIST“).

Caire – content aware image resize library

Caire is content aware image resize library.

How does it works

  • An energy map (edge detection) is generated from the provided image.
  • The algorithm tries to find the least important parts of the image taking into account the lowest energy values.
  • Using a dynamic programming approach the algorithm will generate individual seams accrossing the image from top to down, or from left to right (depending on the horizontal or vertical resizing) and will allocate for each seam a custom value, the least important pixels having the lowest energy cost and the most important ones having the highest cost.
  • Traverse the image from the second row to the last row and compute the cumulative minimum energy for all possible connected seams for each entry.
  • The minimum energy level is calculated by summing up the current pixel with the lowest value of the neighboring pixels from the previous row.
  • Traverse the image from top to bottom and compute the minimum energy level. For each pixel in a row we compute the energy of the current pixel plus the energy of one of the three possible pixels above it.
  • Find the lowest cost seam from the energy matrix starting from the last row and remove it.
  • Repeat the process.

AutoMapper – Declarative data mapper for PHP 7

AutoMapper can map data from array/object to existing array/object or marshal a new one.

Mapping rules specified in declarative way using three simple definitions:

  • From definition (From::create or via short function from) — maps single field from source to target. Supports chainable functions:
    • ->convert(callable $callable) — converts input value to another one via any callable;
    • ->trim() — trims value to eliminate whitespaces (suitable for strings);
    • ->default($defaultValue) — returns default value if source field is missing;
    • ->ignoreMissing() — ignores target field if source field is missing;
    • ->ignoreEmpty() — ignores target field if source field is empty.
  • Aggregate definition (Aggregate::create or via short function aggregate) — maps multiple fields from source to single target field. Supports chainable functions:
    • ->trim() — trims aggregated value
    • ->ignoreEmpty() — ignores target field if aggregated value is empty.
  • Value definition (Value::create or via short function value) — maps constant value to target field. Supports chainable functions:
    • ->trim()
    • ->ignoreEmpty()

All missing source fields can be ignored via AutoMapper::create(...)->ignoreAllMissing() modifier.