Skip to content

u/ChiperSoft

In this archive from Mar 2010 to Jan 2017

13
posts
575
comments
1
media
2.1k
score

Should each service have its own data store?

In terms of the kinds of microservices you'd be producing with PHP, yes, that's kind of the idea. Each service acts as an api interface for a specific data source.

However, I have another example that counters this. I have two microservices that I wrote in NodeJS due to their real-time behavior.

The first is a search service which performs dozens of queries in parallel to take advantage of multiple database cores and different indexes. As the queries finish the results get streamed to the front-end via a long polling system. This way when someone enters a search query, the fastest and most likely cases (like an order id or address) show up first and then less likely matches like full text searches come in over time.

The second is a Socket.io server which manages the data on our order pipeline. It regularly polls the database with a collection of queries, comparing the results against the previous poll. Any differences get broadcast over the websockets to the front-end which updates the order listings. It also manages lock states on orders so that two staffers don't work on the same order.

Both of these systems interact with the same MySQL database as our PHP monolith, but having them as microservices allowed each to fulfil a very small domain of responsibility. If one of them breaks down it doesn't affect anything else on the site.

0 points

I got your point entirely, you're saying that when you have query B that depends on data from query A, you have to wait for query A to finish.

However that is not a scenario that occurs 100% of the time. In the average REST app it's probably not even 50% of the time, as you're far more likely to have more GETs than POSTs. I have numerous routes that perform parallel data lookups. I've got integration tests that interleave a dozen queries at once (including inserts) to setup test conditions.

You could claim that the ability to perform parallel queries wont result in a significant improvement, and that would fall well within the bounds of YMMV, but to claim that parallel query execution is a fallacy is an absolutist generalization and outright misleading.

1 points

It's not a fallacy. Multi-threaded multi-core database systems are fully capable of performing multiple queries at the same time, they do it all the time.

If I need to perform 3 database selects to get the data that I need for a request then yes triggering each query will happen in a synchronous order, but sending those queries to the database takes less than a millisecond. As soon as the first command is sent we can then send the second, and then the third. The parallel processing occurs in the external system, and the database responds in order of how long the query took. The total response time is that of the longest query, not the combined length of all three.

Illustration

1 points

I would say this is a minimum tech stack.

You would be wrong.

First of all, the frontend side of this is almost irrelevant. I say almost because you mentioned a desire to share code between both sides of the site. In 3 years doing node dev I've not yet encountered a single solution for universal JS which isn't a massive clusterfuck of over-engineering (especially the React stuff). It's a pipe-dream

In the real world most of your frontend code is going to be separate from your backend, just like it would be in PHP. Frontend tooling like gulp and webpack, or tools like karma for running frontend tests, are going to be exactly the same for a PHP application running the same logic using the same HTTP requests. The only differences are on the server.

Nginx is a piece of both stacks, so that's irrelevant. NPM comes with node and thus shouldn't be mentioned separately, but if you must then it falls in the exact same position as composer. So, again, irrelevant. MySQL is also part of both stacks... irrelevant.

The absolute minimum that you need to setup a server side application in Node is express + body-parser + a database driver (node-mysql2, for example).

You might want some kind of template library, but as of node 4 JS template strings are available, so you don't really need it. You'll also likely want to use lodash to fill in for the gaps in JS's standard kit, but with Node 6 you have full access to ES6 and some of ES7, which significantly improves the toolkit.

That's it, 3-5 libraries and you can have a fully functional website. Compare that to your average Symfony or Laravel stack and it's a pretty huge difference.

You don't need typescript any more than you need type hinting in PHP. People have been writing both JS and PHP for decades without static types, it's perfectly acceptable.

You don't need mocha, chai or sinon for testing, Node has its own assert module built right in and you can execute multiple test files using shell wildcards. These libraries are just nice-to-haves (and aren't even the best tools available, just the most well known). You probably will need proxyquire, however, to do in-module dependency injection for your tests.

3 points

That's not the point he was making at all. He stresses multiple times in the post is that dynamic languages allow for faster development, and that through TDD you can avoid the issues that static types protect you from.

The article is only about developer efficiency, not anything else.

2 points

Tests tell me if the code I wrote is broken. Types can tell me if the code I am writing is broken.

I believe that's why Bob is stressing TDD, not just testing.

2 points

I've never heard of Robo, but I like gulp a lot. Gives you a lot more flexibility than grunt, and is significantly faster.

5 points

Take note of the age of this post, and its revision history. He wrote this because of reactions when Underscore 1.7 had numerous breaking changes that screwed over people who were using semver in their project dependencies.

Six months later (to the week) Underscore 1.8 was released, containing numerous breaking changes that once again wreaked havok in hundreds of codebases that were relying on Semver. It was also pushed out with numerous bugs, because he ignored failing unit tests. This was when he made the last edit, crossing out the comment about 1.7 becoming 2.0.

Moral of the story, if you use Underscore you better lock the version number, because Jeremy doesn't give a fuck.

Node doesn't follow SemVer

This is no longer true, the next major release of node will follow SemVer.

11 points

It really does depend on how you define community. The main definition is simply a group of people living in the same place or having something in common, and under that definition, any one who uses PHP would be a member of the php community.

Usually, however, when people refer to communities in programming, they mean it in the communal sense of fellowship and contribution, either in the form of knowledge or product. If you are creating open source libraries for other community members to use, you are contributing. If you are helping others to learn more, you are contributing.

A person who partakes of the communal goods but never gives back in kind is a tourist.

A person on an island that doesn't partake of anything and has no communication is an alien.

1 points

Object wrapped literals, ala JavaScript. If a variable containing a string, integer, float or array is addressed as if it were an object, the runtime automatically wraps it in an object for that type (String, Integer, Float, Array). Those object contain OOP versions of all the functions we currently use for those types. This creates a parity with the functional versions of the Mysqli and DateTime functions.

$foo = 'my text';
echo $foo->ucwords();
// My Text
3 points

No specific strategy, but I did get involved in online communities with a lot of other remote developers; Networking helps a lot. The latest job I'm in actually came from a blog post I wrote that the project lead found.

I'm a systems architect, both front-end and backend.

I live in Southern California, but I could probably be anywhere. The current company I work for is about 30 miles north of me, and my last job was for a company in Buffalo, NY.

1 points

Keyboard shortcuts

Move and act

jork
Next / previous post or comment
Enteroro
Open the post
f
Open the media viewer
s
Save
h
Hide (the toast has Undo)
Tab
Right after an action: the toast's Undo
x
Collapse the comment
v
Next layout: cards, compact, grid

Go to

/
Search
gthenh
Home
gthena
All
gthens
Subreddits
gthenl
Library
?
This list
Esc
Close a menu or this list

In the viewer

←or→
Previous / next file
↑or↓
Previous / next post
korj
Previous / next post
Space
Play / pause
m
Mute
z
Zoom
s
Save
o
Open the post (on its own page: back to it)
Esc
Close

Keys do nothing while you type in a box.