News for hackers. Stuff that matters.
Re:Google pub/sub released an ordering feature by staticassertion on Friday October 02, 2020 @01:02AM (#24659059)
What's a use case where strict ordering is critically important?
Re:Google pub/sub released an ordering feature by jerf on Friday October 02, 2020 @10:31AM (#24662986)
"What's a use case where strict ordering is critically important?"

In general, as the use case grows, every use case where the developers did not make explicit and careful provision for ensuring that order is not important, with quite non-trivial effort.

Even a lot of systems whose developers think they have no ordering dependencies are wrong in at least one subtle way without realizing it.

If you need to megascale, you're going to have to bite the bullet and build a system that can handle out-of-order, but there's a lot of systems out there where you don't need megascale, and you can get rid of that "quite non-trivial effort" to deal with out-of-orderness by asking for messages to arrive in order.

To get a sense of just how useful that can be... bear in mind that every time you open a TCP socket instead of a UDP one, you just made exactly that choice, to use an ordered message system when you didn't "need" one. Take a look at everything you do with a TCP socket and think about trying to run it over UDP, and not with something like QUIC that basically adds half of TCP back on it, but with UDP straight-up. That's what kind of things can use in-order delivery... lots of things.

Almost everything can be simplified by guaranteed in-order delivery. It's just that some things can't afford the downsides.

Re:Google pub/sub released an ordering feature by staticassertion on Friday October 02, 2020 @11:57AM (#24663930)
I can understand your post, but I don't quite buy the TCP thing. I don't think anyone is using TCP for ordering, they're using it because they don't want their packet dropped.

I guess all of the systems I build are just built to assume no order/ or to leverage causal ordering, because that feels much easier to reason about - enforcing ordering feels really hard, and like something that a message bus can only do some of the work of.

Re:Google pub/sub released an ordering feature by zeroxfe on Friday October 02, 2020 @12:10PM (#24664063)
> I can understand your post, but I don't quite buy the TCP thing. I don't think anyone is using TCP for ordering, they're using it because they don't want their packet dropped.

Think of (almost) any modern protocol built on top of TCP, and you'll see that ordering is critical. (http, smtp, telnet/ssh, etc.)

Re:Google pub/sub released an ordering feature by staticassertion on Friday October 02, 2020 @01:25PM (#24664857)
Gotcha, ok so specifically protocols built on TCP.
Re:Google pub/sub released an ordering feature by heavenlyblue on Friday October 02, 2020 @12:28PM (#24664250)
There's no ordering in HTTP. If you could send a whole HTTP request as a UDP packet you'd get exactly the same protocol (obviously sans WebSockets - but you could work around that).
Re:Google pub/sub released an ordering feature by duijf on Friday October 02, 2020 @01:16PM (#24664766)
There are numerous valid HTTP payloads that are larger than a single TCP/UDP packet.

Ordering is important in these cases.

Re:Google pub/sub released an ordering feature by heavenlyblue on Saturday October 03, 2020 @09:28AM (#24671955)
I think I made a point that “if you could fit the whole HTTP request in one UDP packet”, have you read my message?
Re:Google pub/sub released an ordering feature by 0xEFF on Friday October 02, 2020 @01:44PM (#24665029)
How would you process an unordered response?
Re:Google pub/sub released an ordering feature by heavenlyblue on Saturday October 03, 2020 @09:35AM (#24671989)
As I have said - you fit in in a single datagram
Re:Google pub/sub released an ordering feature by whatshisface on Friday October 02, 2020 @12:54PM (#24664529)
I'm not sure that ordering doesn't matter for most TCP data. For example, HTTP depends on ordering. Any time you are transmitting messages larger than the size of a packet, you need some degree of ordering, even if it's only to reconstruct the individual messages, when you don't care about the order of the messages.
Re:Google pub/sub released an ordering feature by trimbo on Friday October 02, 2020 @01:11AM (#24659103)
Consider processing two events without guaranteed ordering:

- Create A

- Delete A

In one ordering, A is created and then deleted as expected, in the other, the delete fails but then A is created and remains.

Re:Google pub/sub released an ordering feature by chimera77 on Friday October 02, 2020 @02:15AM (#24659486)
There are a couple of options without needing guaranteed ordering:

- jobs can have ever increasing ids, workers record the last seen id in one place, and ignore jobs with ids less than last seen

- job results are returned for each job to a supervisor. if a job result doesn't match current expected state, resend job. jobs should be idempotent in case a job is sent multiple times

If the create job is expensive, the latter solution would be less ideal, though.

Re:Google pub/sub released an ordering feature by manigandham on Friday October 02, 2020 @03:27AM (#24659975)
Just ignoring tasks isn't helpful, it means you still process things out of order and just never get to the previous pending item in that case.

Much easier to just have strict order and process it off the line as it comes.

Re:Google pub/sub released an ordering feature by bgdam on Friday October 02, 2020 @03:31AM (#24660013)
Creating ever increasing ids reliably at scale is not trivial. You will probably end up having a single server generating these ids which will then become a single point of failure.
Re:Google pub/sub released an ordering feature by caturopath on Friday October 02, 2020 @11:53AM (#24663879)
(Or a distributed system - this is no trickier to migrate away from SPOF than anything else with global state.)
Re:Google pub/sub released an ordering feature by zaphirplane on Friday October 02, 2020 @03:42AM (#24660092)
But when does the delete enter the queue and when does the Create enter the queue ;)
Re:Google pub/sub released an ordering feature by inopinatus on Friday October 02, 2020 @04:15AM (#24660305)
That doesn’t necessarily require that the entire queue is totally ordered, but the alternatives (such as Virtual Synchrony) are still considered arcane / research topics.
Re:Google pub/sub released an ordering feature by staticassertion on Friday October 02, 2020 @11:59AM (#24663950)
Kinda interesting, I built this just yesterday but with an async "buffer" and "write", and I just used a simple incrementing identifier system.
Re:Google pub/sub released an ordering feature by tyrust on Friday October 02, 2020 @01:44AM (#24659293)
Does adding timestamps not handle this case?
Re:Google pub/sub released an ordering feature by jurre on Friday October 02, 2020 @02:16AM (#24659493)
Now you need to queue up events for some time, reorder them using the timestamp, and then process them. It’s possible, but has overhead in both performance and custom code you’ll have to maintain. If there is no guarantee of order, two separate systems consuming those same events also might get different results, depending on the implementation, that can be problematic
Re:Google pub/sub released an ordering feature by sumtechguy on Friday October 02, 2020 @01:28PM (#24664871)
For a single process on one box with one thread you can use something like that.

If you involve more than 1 box that goes out the window. Sometimes you can still get 'one timestamp' by making something else the owner of the timestamp. It also depends on your resolution of time and the process that does the ingesting. For example if that ingest process has more than one thread to handle things you can still get out of order/sametimestamp if not coded correctly.

Re:Google pub/sub released an ordering feature by jedmeyers on Friday October 02, 2020 @01:55AM (#24659360)
If events are generated by different processes you cannot really guarantee that time is exactly the same for them, unless you do something fancy to ensure that.
Re:Google pub/sub released an ordering feature by zaphirplane on Friday October 02, 2020 @03:42AM (#24660089)
Interesting. The ordering here is when the event was generated or when the event entered the queue ? I think the later and so I think the examples here don’t apply without something on top and a trade off
Re:Google pub/sub released an ordering feature by jedmeyers on Friday October 02, 2020 @12:35PM (#24664330)
The queue entrypoint is not always the same process either, especially in a system like Pub/Sub.
Re:Google pub/sub released an ordering feature by GordonS on Friday October 02, 2020 @03:45AM (#24660114)
With a single producer and consumer, yes - but of course that's seldom the case.

With multiple producers and consumers, clock skew would be an issue, with the time on different machines being off from each other slightly.

One option is to use a single source for generating IDs, but that introduces another failure point, and comes at a hefty performance cost.

Re:Google pub/sub released an ordering feature by dragonwriter on Friday October 02, 2020 @05:01AM (#24660589)
> Does adding timestamps not handle this case?

If you have one message source (a single thread or some kind of coordination), and the messages have lower frequency than the timestamp resolution, yes.

The farther you get from that, the more the answer is no.

Re:Google pub/sub released an ordering feature by amelius on Friday October 02, 2020 @08:15AM (#24661819)
Just make the source part of the timestamp?

(1,A) < (1,B) < (2,A) etc.

Also use serial numbers instead of true timestamps.

Re:Google pub/sub released an ordering feature by rsynnott on Friday October 02, 2020 @11:15AM (#24663488)
That way lies madness, and/or eventually accidentally writing your own Dynamo-paper database.
Re:Google pub/sub released an ordering feature by valleyjo on Friday October 02, 2020 @02:28AM (#24659565)
That won’t work in all cases. For instance, if you get messages from devices which can be reimaged they may have clock skew in a period of time before they’re synchronized again.
Re:Google pub/sub released an ordering feature by easytiger on Friday October 02, 2020 @04:31AM (#24660400)
But in any case you can't rely on the order of message ingress to your system to represent anything meaningful either? It would have to ensure that the key for defining order would have some hard logical ordering purpose for which time is not relevant or useful.
Re:Google pub/sub released an ordering feature by jlokier on Friday October 02, 2020 @12:08PM (#24664043)
The order of message ingress can still be meaningful even if device clocks are skew or jump due to rebooting, reimaging, network time sync, frequency drift, etc.

A hard logical order arises from interactions. E.g. if the device receives a message, does something locally, goes through a clock change, and then sends a message dependent on one it fetched earlier, that's a logical order with out-of-order clock.

Or if a device gets a message, processes, sends something to another device, that one processes too then sends another message back to the original source, there's a logical order but with three different clocks. Even if the clocks are synchronised, there will be some drift and the messages may be processed fast enough that the drift puts their timestamps out of order.

Re:Google pub/sub released an ordering feature by easytiger on Friday October 02, 2020 @02:45PM (#24665711)
That guarantee/assumption can never really be made.

Message A on event a' from system a might be sent to system b effecting event b' and thus message B to be sent by <insert medium here>, and consumed and correlated by consumer software MC on hardware mc.

However system B might take longer to flush it's hardware/software buffer and the message arrives at mc before message A, for example.

I've encountered this many times. That data has no meaning in itself except in the meta.

> Even if the clocks are synchronised, there will be some drift and the messages may be processed fast enough that the drift puts their timestamps out of order.

If you are consuming from sources which you cannot control the accuracy of the clocks, then you must inherently either reduce your reliance on the need for accuracy (many Windows systems have horrendous clock discipline in their software implementation) or find a way of ensuring accuracy. E.g. close proximity NTP or close proximity PTP etc etc.

Hope that makes sense.

Re:Google pub/sub released an ordering feature by jlokier on Friday October 02, 2020 @03:41PM (#24666334)
I think you and I are agreeing, but it's not obvious ;-)

> However system B might take longer to flush it's hardware/software buffer and the message arrives at mc before message A, for example.

There are two message As in your system, the one sent to system b, and the one consumed by hardware mc. Let's call them Ab and Amc.

In that situation, message B is a consequence of message Ab which can be tracked, and at system mc (depending on semantics) it might be necessary to use that tracking to process message Amc before message B, at least logically.

For example message Ab/Amc might be "add new user Foo the our database with standard policy", and system B might react with "ok, my job is to set the policy for new users, I'll tell mc to add permission Bar to user Foo then activate Foo".

That works out fine as long as the logical order relation is maintained, and system mc, the database, processes message Amc first, regardless of arrival order.

Dependency tracking can ensure that (without clocks or timestamps), even if messages are transmitted independently. For example by message B containing a header that says it comes logically after message A.

The pubsub queue can also guarantee that order (without clocks or timestamps or dependency tracking), provided all messages go through the same pubsub system, and Ab+Amc are fanned-out by the pubsub system rather than sent independently by A to each destination. All bets are off if Ab and Amc take other routes.

> If you are consuming from sources which you cannot control the accuracy of the clocks, then you must inherently either reduce your reliance on the need for accuracy (many Windows systems have horrendous clock discipline in their software implementation) or find a way of ensuring accuracy. E.g. close proximity NTP or close proximity PTP etc etc.

If you think Windows is bad, try just about any cloud VM, which has a virtual clock and is stalled all the time in the guest, including just after the guest reads its virtual clock and before using the value :-)

I prefer systems which rely on logical ordering guarantees as much as possible, so clock drift doesn't matter.

When you are rely on a global clock order to ensure correct behaviour, you have to slow down some operations to accommodate for clock variance across the system, as well as network latency variance (because it affects clock synchronisation).

If you rely on logical order, then there's no need for time delays; no upper speed limit. Instead you have to keep track of dependencies, or have implicit causal dependencies. And it's more robust on real systems because clock drift and jumps don't matter.

In practice you need some clock dependence for timeouts anyway, and there are protocol advantages when you can depend on a well synchronised clock. So I prefer to mix the two for different layers of the protocol, to get advantages of both. Unfortunately for correct behaviour, timeouts are often the "edge case" that isn't well tested or correctly implemented at endpoints.

Re:Google pub/sub released an ordering feature by baq on Friday October 02, 2020 @11:23AM (#24663559)
every use case where you haven't proven it isn't.

human conscious thought is local and single-threaded. it takes a lot of experience and training to be able to intuitively reason about non-local multi-threaded computation. if you're smart and humble you can try to simplify the problem by making individual messages independent from each other by e.g. employing redundancy but you still have to be aware that it's even a problem to begin with.

Re:Google pub/sub released an ordering feature by kurttheviking on Friday October 02, 2020 @01:36AM (#24659248)
I see it a lot when integrating legacy healthcare systems that effectively operate on state-transition queues with an assumption of in-order processing.
Re:Google pub/sub released an ordering feature by himoacs on Friday October 02, 2020 @09:48AM (#24662538)
Financial transactions (withdrawing/depositing money or placing stock orders) Credit card/payment usecases